Java Cross Hatching Texture
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.
如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

评论(1)

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);
发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。