开发者

How to set different strokes on a Java 2D GeneralPath?

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 开发者_StackOverflow中文版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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜