【问题标题】:Ugly font rendering丑陋的字体渲染
【发布时间】:2019-08-23 10:00:14
【问题描述】:

我一直在尝试在我的 WinForm 应用程序上获取自定义字体。但是,似乎无论我做什么,字体都无法正确呈现。它是.ttf 并且确实显示在我的标签上,但不是很好。

我关注了这个StackOverflow answer,但这是我得到的结果:

底部“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);

【问题讨论】:

    标签: c# winforms fonts rendering


    【解决方案1】:

    我认为这太明显了……我的问题是我的字体大小是6F8F,因为我认为奇数不是正确的大小。我所要做的就是将其更改为7F

    因此,如果您的像素字体看起来很难看,我会保留这篇文章作为警告。仔细检查您是否输入了正确的字体大小。

    注意:如果您没有将属性UseCompatibleTextRendering 设置为True,您的字体也可能看起来有些失真)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 2012-09-07
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多