如何在 Java 2D GeneralPath 上设置不同的笔画?
我想用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法在一次调用
Graphics2D.draw
中绘制具有两种不同线宽的路径的两个部分。您必须通过两次调用来完成此操作。您也许可以通过以不同方式设置线路的上限来解决连接问题,例如设置为圆形。如果执行此操作,并且两条线在同一点结束,则圆形边缘应覆盖末端并使其看起来更好。只要您不使用 alpha 值来设置透明度,这应该会很好用。如果您使用透明胶片,上述方法会使连接变暗,因为它被绘制了两次。在这种情况下,您可以尝试不同的方法。定义一种形状并使用 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.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.