如何在 Graphics2D 中制作像素完美的 Line2D
你好,我有 JPanel,上面有一些 Line2D 对象。问题是当我画这条线时,它并没有按照我想要的方式显示。线条不流畅,很难用文字解释,所以我发布了一张图片,
缩放区域,
< img src="https://i.sstatic.net/1iP33.png" alt="在此处输入图像描述">
如何使它们看起来更光滑而不是起皱。
谢谢
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,
Zoomed Area,
How to make them look more polished rather than wrinkly.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是您的图形上下文没有打开抗锯齿功能。在绘制之前尝试以下行:(
当然,其中
graphics
是您的 Graphics2D 实例)。稍后,当您发现您正在绘制的文本也很丑陋且呈锯齿状时,您会想要使用
然而,文本有点复杂;您可以使用此提示的多个值,具体取决于(除其他外)您将文本绘制到的屏幕类型。您应该阅读
RenderingHints.KEY_TEXT_ANTIALIASING< /code> API 文档
了解这些详细信息。
The problem is likely that you don't have antialiasing turned on your Graphics context. Try the following line before you draw:
(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
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.