views:

477

answers:

1

Any know how to recreate a cross hashing texture in Java? The C# code belows shows how to accomplish this for the .NET framework. The Java snippet is close, but I've been unable to correctly rotate the lines by 45 degrees.

C#

HatchBrush crossHatch =
        new HatchBrush(HatchStyle.Cross, somecolor, somecolor);

Java

BufferedImage bufferedImage =
        new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);

Graphics2D g2 = bufferedImage.createGraphics();

g2.setColor(Color.BLUE);
g2.fillRect(0, 0, 5, 5);
g2.setColor(pinColor);
g2.fillOval(0, 0, 5, 5);

// paint with the texturing brush
Rectangle2D rect = new Rectangle2D.Double(0, 0, 5, 5);
g2d.setPaint(new TexturePaint(bufferedImage, rect));
g2d.fill(shape);

Thanks in advance.

+1  A: 

Here's one that should cross-hatch at 5-pixel intervals:

BufferedImage bufferedImage =
        new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);

Graphics2D g2 = bufferedImage.createGraphics();
g2.setColor(backColor);
g2.fillRect(0, 0, 5, 5);
g2.setColor(stripeColor);
g2.drawLine(0, 0, 5, 5); // \
g2.drawLine(0, 5, 5, 0); // /

// paint with the texturing brush
Rectangle2D rect = new Rectangle2D.Double(0, 0, 5, 5);
g2d.setPaint(new TexturePaint(bufferedImage, rect));
g2d.fill(shape);
Michael Myers