Java交叉孵化纹理

时间:2009-04-27 18:46:53

标签: java graphics rendering

任何人都知道如何在Java中重新创建交叉散列纹理?下面的C#代码显示了如何为.NET框架实现此目的。 Java片段很接近,但我无法正确地将线条旋转45度。

C#

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

爪哇

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);

提前致谢。

1 个答案:

答案 0 :(得分:10)

这是一个应该以5像素间隔交叉影线的那个:

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);