如何在 Graphics2D 中制作像素完美的 Line2D

发布于 2024-12-03 10:23:43 字数 283 浏览 3 评论 0原文

你好,我有 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,

enter image description here

Zoomed Area,

enter image description here

How to make them look more polished rather than wrinkly.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲凉≈ 2024-12-10 10:23:43

问题可能是您的图形上下文没有打开抗锯齿功能。在绘制之前尝试以下行:(

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

当然,其中 graphics 是您的 Graphics2D 实例)。

稍后,当您发现您正在绘制的文本也很丑陋且呈锯齿状时,您会想要使用

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

然而,文本有点复杂;您可以使用此提示的多个值,具体取决于(除其他外)您将文本绘制到的屏幕类型。您应该阅读 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文