如何使像素完美Line2D - Graphics2D [英] How to make pixel perfect Line2D in - Graphics2D
问题描述
G'day,我有JPanel,上面有一些Line2D对象。问题是,当我画这条线时,它不会像我想要的那样出现。线条不平滑,很难解释,所以我发布了一张图片,
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 them look more polished rather than wrinkly.
谢谢
推荐答案
问题可能是你没有有抗锯齿功能打开你的图形上下文。在绘制之前尝试以下行:
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);
(其中,当然,图形
是你的Graphics2D实例)。
(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);
然而,文字有点复杂;这个提示有几个值,你可以根据(除其他外)你正在绘制文本的屏幕类型来使用。您应该阅读 RenderingHints这些细节的.KEY_TEXT_ANTIALIASING
API doc 。
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.
这篇关于如何使像素完美Line2D - Graphics2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!