java类java.awt.TexturePaint的实例源码

RenderTests.java 文件源码 项目:infobip-open-jdk-8 阅读 24 收藏 0 点赞 0 评论 0
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
RenderTests.java 文件源码 项目:jdk8u-dev-jdk 阅读 26 收藏 0 点赞 0 评论 0
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
ColorUtil.java 文件源码 项目:aibench-project 阅读 41 收藏 0 点赞 0 评论 0
public static Paint getCheckerPaint(Color c1, Color c2, int size) {
    BufferedImage img = new BufferedImage(size,size,BufferedImage.TYPE_INT_ARGB);
    Graphics g = img.getGraphics();

    try {
        g.setColor(c1);
        g.fillRect(0, 0, size, size);
        g.setColor(c2);
        g.fillRect(0, 0, size / 2, size / 2);
        g.fillRect(size / 2, size / 2, size / 2, size / 2);
    } finally {
        g.dispose();
    }

    return new TexturePaint(img,new Rectangle(0,0,size,size));
}
SVGPaint.java 文件源码 项目:feathers-sdk 阅读 20 收藏 0 点赞 0 评论 0
/**
 * @param paint Paint to be converted to SVG
 * @return a descriptor of the corresponding SVG paint
 */
public SVGPaintDescriptor toSVG(Paint paint){
    // we first try the extension handler because we may
    // want to override the way a Paint is managed!
    SVGPaintDescriptor paintDesc = svgCustomPaint.toSVG(paint);

    if (paintDesc == null) {
        if (paint instanceof Color)
            paintDesc = SVGColor.toSVG((Color)paint, generatorContext);
        else if (paint instanceof GradientPaint)
            paintDesc = svgLinearGradient.toSVG((GradientPaint)paint);
        else if (paint instanceof TexturePaint)
            paintDesc = svgTexturePaint.toSVG((TexturePaint)paint);
    }

    return paintDesc;
}
RenderTests.java 文件源码 项目:jdk7-jdk 阅读 26 收藏 0 点赞 0 评论 0
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
Bitmap.java 文件源码 项目:BattleNationsAnimation 阅读 19 收藏 0 点赞 0 评论 0
private void read() throws IOException {
    LittleEndianInputStream in = new LittleEndianInputStream(
            GameFiles.open(name + "_0.z2raw"));
    try {
        int ver = in.readInt();
        if (ver < 0 || ver > 1)
            throw new FileFormatException("Unrecognized version");
        width = in.readInt();
        height = in.readInt();
        bits = in.readInt();
        BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        if (ver == 0)
            readRaw(im, in);
        else
            readRLE(im, in);
        texture = new TexturePaint(im, new Rectangle2D.Double(0, 0, 0x8000, 0x8000));
        originalTexture = texture;
    }
    catch (ArrayIndexOutOfBoundsException e) {
        throw new FileFormatException("Invalid array index", e);
    }
    finally {
        in.close();
    }
}
ImageUtils.java 文件源码 项目:jMCS 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Create a cross hatched texture
 * @param size internal image size (height = width)
 * @param backgroundColor background color
 * @param stripeColor line color
 * @param stroke line stroke
 * @return cross hatched texture paint
 */
public static Paint createHatchedTexturePaint(final int size, final Color backgroundColor, final Color stripeColor, final Stroke stroke) {

    // create buffered image (alpha):
    final BufferedImage bufferedImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = bufferedImage.createGraphics();

    // LBO: use antialiasing:
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    g2d.setColor(backgroundColor);
    g2d.fillRect(0, 0, size, size);

    g2d.setStroke(stroke);
    g2d.setColor(stripeColor);
    g2d.drawLine(0, 0, size, size);
    g2d.drawLine(0, size, size, 0);

    g2d.dispose();

    return new TexturePaint(bufferedImage, new Rectangle(0, 0, size, size));
}
RenderTests.java 文件源码 项目:openjdk-source-code-learn 阅读 22 收藏 0 点赞 0 评论 0
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
DrawingAttributes.java 文件源码 项目:passage 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Get the Paint for these attributes, and scale it for the scale compared to
 * the base scale set if the fill Paint is a TexturePattern. If the base
 * scale equals NONE, or if the Paint is not a TexturePaint, it's the same as
 * getFillPaint().
 * 
 * @param scale scale to compare to the base scale.
 * @return a Paint object to use for the fill, scaled if necessary.
 */
public Paint getFillPaintForScale(float scale) {
   if (fillPattern != null) {
      if (baseScale != NONE) {
         BufferedImage bi = fillPattern.getImage();
         float scaleFactor = scale / baseScale;
         Image image =
               bi.getScaledInstance((int) (bi.getWidth() * scaleFactor), (int) (bi.getHeight() * scaleFactor),
                                    Image.SCALE_SMOOTH);
         try {
            bi = BufferedImageHelper.getBufferedImage(image, 0, 0, -1, -1);

            return new TexturePaint(bi, new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
         } catch (InterruptedException ie) {
            if (logger.isLoggable(Level.FINE)) {
               logger.warning("DrawingAttributes: Interrupted Exception scaling texture paint");
            }
         }
      }
      return fillPattern;
   } else {
      return fillPaint;
   }
}
RenderTests.java 文件源码 项目:OLD-OpenJDK8 阅读 24 收藏 0 点赞 0 评论 0
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}


问题


面经


文章

微信
公众号

扫码关注公众号