Search in sources :

Example 1 with TexturePaint

use of java.awt.TexturePaint in project gephi by gephi.

the class GradientSliderUI method createCheckerPaint.

private static void createCheckerPaint() {
    int k = 4;
    BufferedImage bi = new BufferedImage(2 * k, 2 * k, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, 2 * k, 2 * k);
    g.setColor(Color.lightGray);
    g.fillRect(0, 0, k, k);
    g.fillRect(k, k, k, k);
    checkerPaint = new TexturePaint(bi, new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
}
Also used : TexturePaint(java.awt.TexturePaint) Rectangle(java.awt.Rectangle) TexturePaint(java.awt.TexturePaint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 2 with TexturePaint

use of java.awt.TexturePaint in project jdk8u_jdk by JetBrains.

the class TexturePaintPrintingTest method doPaint.

public void doPaint(Graphics2D g2d) {
    BufferedImage patternImage = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
    Graphics gImage = patternImage.getGraphics();
    gImage.setColor(Color.WHITE);
    gImage.drawLine(0, 1, 1, 0);
    gImage.setColor(Color.BLACK);
    gImage.drawLine(0, 0, 1, 1);
    gImage.dispose();
    Rectangle2D.Double shape = new Rectangle2D.Double(0, 0, DIM * 6 / 5, DIM * 8 / 5);
    g2d.setPaint(new TexturePaint(patternImage, new Rectangle2D.Double(0, 0, DIM * 6 / 50, DIM * 8 / 50)));
    g2d.fill(shape);
    g2d.setPaint(Color.BLACK);
    g2d.draw(shape);
}
Also used : Graphics(java.awt.Graphics) TexturePaint(java.awt.TexturePaint) Rectangle2D(java.awt.geom.Rectangle2D) BufferedImage(java.awt.image.BufferedImage)

Example 3 with TexturePaint

use of java.awt.TexturePaint in project jdk8u_jdk by JetBrains.

the class TransformedPaintTest method createPaint.

private Paint createPaint(PaintType type, int startx, int starty, int w, int h) {
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++;
    h++;
    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch(type) {
        case COLOR:
            return Color.red;
        case GRADIENT:
            return new GradientPaint(startx, starty, Color.red, endx, endy, Color.green);
        case LINEAR_GRADIENT:
            return new LinearGradientPaint(startx, starty, endx, endy, new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT:
            return new RadialGradientPaint(startx, starty, (float) Math.sqrt(w * w + h * h), new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue }, CycleMethod.NO_CYCLE);
        case TEXTURE:
            {
                BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
                Graphics2D g = (Graphics2D) bi.getGraphics();
                g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
                g.fillRect(0, 0, w, h);
                return new TexturePaint(bi, r);
            }
    }
    return Color.green;
}
Also used : TexturePaint(java.awt.TexturePaint) Rectangle2D(java.awt.geom.Rectangle2D) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) GradientPaint(java.awt.GradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 4 with TexturePaint

use of java.awt.TexturePaint in project poi by apache.

the class HwmfGraphics method getHatchedFill.

protected Paint getHatchedFill() {
    int dim = 7, mid = 3;
    BufferedImage bi = new BufferedImage(dim, dim, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g = bi.createGraphics();
    Color c = (prop.getBkMode() == HwmfBkMode.TRANSPARENT) ? new Color(0, true) : prop.getBackgroundColor().getColor();
    g.setColor(c);
    g.fillRect(0, 0, dim, dim);
    g.setColor(prop.getBrushColor().getColor());
    HwmfHatchStyle h = prop.getBrushHatch();
    if (h == HwmfHatchStyle.HS_HORIZONTAL || h == HwmfHatchStyle.HS_CROSS) {
        g.drawLine(0, mid, dim, mid);
    }
    if (h == HwmfHatchStyle.HS_VERTICAL || h == HwmfHatchStyle.HS_CROSS) {
        g.drawLine(mid, 0, mid, dim);
    }
    if (h == HwmfHatchStyle.HS_FDIAGONAL || h == HwmfHatchStyle.HS_DIAGCROSS) {
        g.drawLine(0, 0, dim, dim);
    }
    if (h == HwmfHatchStyle.HS_BDIAGONAL || h == HwmfHatchStyle.HS_DIAGCROSS) {
        g.drawLine(0, dim, dim, 0);
    }
    g.dispose();
    return new TexturePaint(bi, new Rectangle(0, 0, dim, dim));
}
Also used : TexturePaint(java.awt.TexturePaint) Color(java.awt.Color) Rectangle(java.awt.Rectangle) HwmfHatchStyle(org.apache.poi.hwmf.record.HwmfHatchStyle) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 5 with TexturePaint

use of java.awt.TexturePaint in project jdk8u_jdk by JetBrains.

the class RenderTests method makeTexturePaint.

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);
}
Also used : TexturePaint(java.awt.TexturePaint) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) TexturePaint(java.awt.TexturePaint) RadialGradientPaint(java.awt.RadialGradientPaint) MultipleGradientPaint(java.awt.MultipleGradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

TexturePaint (java.awt.TexturePaint)9 BufferedImage (java.awt.image.BufferedImage)7 Color (java.awt.Color)4 Graphics2D (java.awt.Graphics2D)4 Paint (java.awt.Paint)4 Rectangle (java.awt.Rectangle)4 Rectangle2D (java.awt.geom.Rectangle2D)4 GradientPaint (java.awt.GradientPaint)3 LinearGradientPaint (java.awt.LinearGradientPaint)3 RadialGradientPaint (java.awt.RadialGradientPaint)3 MultipleGradientPaint (java.awt.MultipleGradientPaint)2 AlphaComposite (java.awt.AlphaComposite)1 BasicStroke (java.awt.BasicStroke)1 Composite (java.awt.Composite)1 Graphics (java.awt.Graphics)1 Shape (java.awt.Shape)1 AffineTransform (java.awt.geom.AffineTransform)1 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)1 WritableRaster (java.awt.image.WritableRaster)1 HwmfHatchStyle (org.apache.poi.hwmf.record.HwmfHatchStyle)1