用拉链绘画看起来不好

发布于 2025-01-21 20:30:55 字数 428 浏览 0 评论 0 原文

drawstring 的结果具有相同的字体和大小在Java中 当画家(或单词)中使用相同的字体和大小绘制时,外观是不同的。在Java中用牵引线绘制看起来不好。

为什么看起来如此不同?

有没有办法使它看起来像一个单词或Java中的画家?

顶部是在Java中绘制的,较低的画面是用画家绘制的。

代码:

    Font fontBold28 = new Font("Arial", Font.BOLD|Font.ITALIC, 28);

    g.setFont(fontBold28);
    g.setColor(Color.black);
    g.drawString("ABCDEFG", x, y);

The result of drawString with the same font and size in java
The appearance is different when drawn with the same font and size in a painter (or word). Drawing with drawstring in java doesn't look good.

Why does it look so different?

Is there a way to make it look nice like a word or a painter in java?

The top one is drawn in Java, the lower one is painted in painter.

Code:

    Font fontBold28 = new Font("Arial", Font.BOLD|Font.ITALIC, 28);

    g.setFont(fontBold28);
    g.setColor(Color.black);
    g.drawString("ABCDEFG", x, y);

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

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

发布评论

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

评论(1

莳間冲淡了誓言ζ 2025-01-28 20:30:55

抗质量。

文本抗质量(也称为字体平滑)是一种渲染引擎模糊角色形状边缘的能力,因此边缘看起来不会锯齿状。

它通常在JAVA2D图形对象中默认情况下关闭,因为它会导致文本绘图较慢,但是在现代计算环境中,该性能差异的重要性少于以前。除非您经常渲染文本,否则您可能不会注意到差异。

您可以使用

Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

Font fontBold28 = new Font("Arial", Font.BOLD|Font.ITALIC, 28);

g.setFont(fontBold28);
g.setColor(Color.black);
g.drawString("ABCDEFG", x, y);

​阅读看到他们全部。 java教程也描述了它们。

Antialiasing.

Text antialiasing, also known as font smoothing, is a rendering engine’s ability to blur the edges of character shapes, so the edges don’t look jagged.

It’s usually off by default in Java2D Graphics objects, because it causes text drawing to be slower, but in modern computing environments, that performance difference matters less than it used to. You probably won’t notice the difference, unless you are rendering text frequently.

You can turn on text antialiasing using the setRenderingHint method of Graphics2D:

Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

Font fontBold28 = new Font("Arial", Font.BOLD|Font.ITALIC, 28);

g.setFont(fontBold28);
g.setColor(Color.black);
g.drawString("ABCDEFG", x, y);

There are many behaviors of drawing that can be controlled by setting rendering hints. Read the RenderingHints documentation to see them all. The Java Tutorial also describes them.

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