开发者

How to make pixel perfect Line2D in - Graphics2D

G'day, I have JPanel with some Line2D objects on it. Issue is when I draw this line it doesn't appear as I want them to. Lines are not smooth, It's hard to 开发者_如何学运维explain in word so I am posting an Image,

How to make pixel perfect Line2D in - Graphics2D

Zoomed Area,

How to make pixel perfect Line2D in - Graphics2D

How to make them look more polished rather than wrinkly.

Thanks


The problem is likely that you don't have antialiasing turned on your Graphics context. Try the following line before you draw:

graphics.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);

(where, of course, graphics is your Graphics2D instance).

Later on when you discover that the text you're drawing is also ugly and jagged, you'll want to use

graphics.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING,
        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

However, text is a little more complicated; there's several values for this hint that you can use depending on (among other things) the type of screen you're drawing the text to. You should read the RenderingHints.KEY_TEXT_ANTIALIASING API doc for those details.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜