如何在 Java 2D GeneralPath 上设置不同的笔画?

发布于 2024-09-15 19:29:55 字数 244 浏览 4 评论 0原文

我想用 GeneralPath 绘制一个数学符号。

GeneralPath gp1 = new GeneralPath();
gp1.moveTo( 50, 10 );
gp1.lineTo( 50, 80 );
gp1.closePath();

现在我想把一条线画得比另一条线粗,并且连接应该看起来不错。让我们采取 <例如,我想要上面的线 / 四倍粗的 \ 线。如果我单独画线,连接看起来是错误的。

I want to draw a math symbol with GeneralPath.

GeneralPath gp1 = new GeneralPath();
gp1.moveTo( 50, 10 );
gp1.lineTo( 50, 80 );
gp1.closePath();

Now I want to draw one line thicker that the other and the connection should look nice. Lets take the < for example where I want the upper line / four times thicker the \ line. If I draw the lines separately the connection looks wrong.

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

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

发布评论

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

评论(1

霓裳挽歌倾城醉 2024-09-22 19:29:55

无法在一次调用 Graphics2D.draw 中绘制具有两种不同线宽的路径的两个部分。您必须通过两次调用来完成此操作。您也许可以通过以不同方式设置线路的上限来解决连接问题,例如设置为圆形。如果执行此操作,并且两条线在同一点结束,则圆形边缘应覆盖末端并使其看起来更好。只要您不使用 alpha 值来设置透明度,这应该会很好用。

g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND);

如果您使用透明胶片,上述方法会使连接变暗,因为它被绘制了两次。在这种情况下,您可以尝试不同的方法。定义一种形状并使用 Graphics2D.fill 并手动设置所有点和弧,使一条线稍微粗一些。你绝对必须打开抗锯齿才能使其工作,而且我不确定它会是什么样子。

There is no way to draw two parts of the path with two different line thicknesses in one call to Graphics2D.draw. You would have to do it in two calls. You might be able to address the connection by setting the cap on the lines differently, like to rounded, for example. If you do this, and the two lines end at the same point, the rounded edge should cover the ends and make it look better. As long as you're not using alpha values to set transparency, this should work great.

g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND);

If you're using transparencies, the above approach would make the join be darker because it's being drawn on twice. In this case, you could try a different approach. Define one shape and use Graphics2D.fill and set all of the points and arcs manually, making one line slightly thicker. You would absolutely have to have anti-aliasing turned on for it to work, and I'm not sure how it would look.

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