c# - 丑陋的字体渲染
问题描述
我一直在尝试在我的 WinForm 应用程序上获取自定义字体。但是,似乎无论我做什么,字体都不会正确呈现。这是一个.ttf
并且确实显示在我的标签上,只是不是很好。
我遵循了这个StackOverflow 答案,但这是我得到的结果:
底部“0%”和“2.6MB”的两个标签都是“Courier New”。正确渲染顶部标签后,我将切换它们。
我的代码与上述答案几乎相同(所有波纹管都在FormLoad中运行):
// Create a private font collection object.
PrivateFontCollection pfc = new PrivateFontCollection();
// Select the font from 'Resources'.
// My font here is "Volter__28Goldfish_29.ttf".
int fontLength = Properties.Resources.Volter__28Goldfish_29.Length;
// Create a buffer to read in to.
byte[] fontdata = Properties.Resources.Volter__28Goldfish_29;
// Create an unsafe memory block for the font data.
IntPtr data = Marshal.AllocCoTaskMem(fontLength);
// Copy the bytes to the unsafe memory block.
Marshal.Copy(fontdata, 0, data, fontLength);
// Pass the font to the font collection.
pfc.AddMemoryFont(data, fontLength);
// Set custom font.
lblUpdate.Font = new Font(pfc.Families[0], 8);
解决方案
我认为这太明显了……我的问题是我的字体大小是6F
或者8F
是,我认为奇数不是正确的大小。我所要做的就是将其更改为7F
.
因此,如果您的像素字体看起来很难看,我会保留这篇文章作为警告。仔细检查您是否输入了正确的字体大小。
(注意:如果您没有将属性设置为 ,您的字体也可能会显得有些UseCompatibleTextRendering
失真True
)
推荐阅读
- android - 如果要写入的对象之一与 Firestore 中的对象具有相同的内容,会发生什么?
- php - 使用 PHP 向 PayPal 结帐发出 POST 请求如何发送身份验证参数?
- java - 当我非常仔细地单击图片时,文本被识别。它甚至无法识别名片上的文字
- r - 尽管设置了种子,但 BSTS 产生不一致的结果(在 R 中)
- jquery - 带有光滑滑块的自定义导航与轮播幻灯片不同步
- python - 在 Altair 中订购条形图?
- debugging - 调试时值类型的意外更改
- java - 每天向 XML 文件添加数据(以性能为重点)
- botframework - 通用 Oauth 2 提供程序 Azure(OAuth 连接设置)BotFramework SDK V4
- hadoop - Hadoop 2.9 多节点