为了账号安全,请及时绑定邮箱和手机立即绑定

字体渲染丑陋

字体渲染丑陋

C#
湖上湖 2023-09-16 20:04:57
我一直在尝试在我的 WinForm 应用程序上获取自定义字体。然而,似乎无论我做什么,字体都无法正确呈现。它确实.ttf显示在我的标签上,只是不太好。这是我得到的结果:底部的两个标签“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);
查看完整描述

1 回答

?
侃侃尔雅

TA贡献1801条经验 获得超15个赞

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

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

注意:如果您未将该属性设置UseCompatibleTextRendering为,您的字体也可能会显得有些扭曲True


查看完整回答
反对 回复 2023-09-16
  • 1 回答
  • 0 关注
  • 40 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信