丑陋的字体渲染

3
我一直在尝试在WinForm应用程序中使用自定义字体。但是,无论我做什么,字体都无法正确呈现。它是一个.ttf文件,并且确实显示在我的标签上,但效果不佳。
我遵循了这个StackOverflow答案,但这是我得到的结果:

底部的两个标签“0%”和“2.6MB”都是“Courier New”。一旦我正确呈现了顶部标签,我就会将它们切换过来。

Ugly font render

我的代码与上述答案几乎相同(所有以下内容都在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);
1个回答

0

我原以为这太明显不可能是真的...我的问题在于我的字体大小要么是6F要么是8F,我认为奇数不可能是正确的大小。我所需要做的就是将它改为7F

因此,我将保留这篇文章作为一个警示,如果你的像素字体看起来很丑,请仔细检查你是否已经设置了正确的字体大小。

(注意:如果没有将属性UseCompatibleTextRendering设置为True,你的字体也可能出现某些失真)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接