GDI+绘制聚集在一起的字母

发布于 2025-01-06 05:25:08 字数 582 浏览 5 评论 0原文

我觉得我读过类似的问题,但我找不到它,所以如果重复请关闭。

我正在尝试使用等宽字体(Consolas)使用 Graphics::DrawString 绘制文本。但是,当我绘制文本时,字母的间距不均匀。它看起来像这样:

在此处输入图像描述

正如您所看到的,这些字母聚集成两个和三个一组。我阅读了这篇文章,我认为我已经采取了足够的步骤来通过使用来避免它StringFormat::GenericTypography,但显然不是。我还使用 TextRenderingHintClearTypeGridFit 因为所有其他看起来都像垃圾(并且没有 TextRenderingHintClearType 没有 GridFit 部分)。

如何像所有其他使用等宽字体绘制文本的程序一样绘制文本,使其看起来正确?

I feel like I've read a question similar to this but I can't find it, so please close if duplicate.

I am trying to draw text with Graphics::DrawString with a monospace font (Consolas). However, when I draw the text, the letters are not evenly spaced. Here's what it looks like:

enter image description here

As you can see, the letters are clustered into groups of two and three. I read this article and I thought I had taken adequate steps to avoid it by using StringFormat::GenericTypographic, but apparently not. I am also using TextRenderingHintClearTypeGridFit because all the others look like junk (and there's no TextRenderingHintClearType without the GridFit part).

How can I draw text like all the other programs that draw text with a monospace font so that it looks right?

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

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

发布评论

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

评论(1

濫情▎り 2025-01-13 05:25:08

问题是 GDI+ 使用不同的(并且早已废弃的)系统来绘制文本。从 .NET Framework 2.0 开始,Microsoft 更改了所有控件,以实际使用 GDI 进行文本渲染,而不是 GDI+。 GDI 中的文本渲染是硬件加速的,并且通过字符渲染、Uniscribe、连字不断得到改进。 GDI+ 中的文本渲染不是硬件加速的,并且没有得到任何修复或改进。

GDI 还可以绘制抗锯齿,使用 CLEARTYPE_QUALITY 或 ANTIALIASED_QUALITY。

的比较

  • 以下是GDI+ (Graphics.DrawString)
  • GDI (TextRenderer.DrawText)

在此处输入图像描述

The issue is that GDI+ uses a different (and long since abandoned) system for drawing text. Starting with .NET framework 2.0, Microsoft changed all the controls to actually use GDI for text rendering, rather than GDI+. Text rendering in GDI is hardware accelerated, and continued to get improvements with character rendering, Uniscribe, ligatures. Text rendering in GDI+ is not hardware accelerated, and not getting any fixes or improvements.

GDI can also draw anti-aliased, use CLEARTYPE_QUALITY or ANTIALIASED_QUALITY.

Here's a comparison of

  • GDI+ (Graphics.DrawString)
  • GDI (TextRenderer.DrawText)

enter image description here

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