Java 交叉剖面线纹理

发布于 2024-07-17 17:20:27 字数 677 浏览 3 评论 0原文

有人知道如何在 Java 中重新创建交叉哈希纹理吗? 下面的 C# 代码展示了如何为 .NET 框架完成此任务。 Java 片段很接近,但我无法正确地将线旋转 45 度。

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

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2024-07-24 17:20:27

下面是应以 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文