C# 将字体系列从磁盘加载到PrivateFontCollection

C# 将字体系列从磁盘加载到PrivateFontCollection,c#,gdi+,privatefontcollection,C#,Gdi+,Privatefontcollection,我使用以下代码将字体加载到内存中,以便使用GDI+生成图像: var fontCollection = new PrivateFontCollection(); fontCollection.AddFontFile(Server.MapPath("~/fonts/abraham-webfont.ttf")); fontCollection.Families.Count(); // => This line tells me, that the collection has 0 items.

我使用以下代码将字体加载到内存中,以便使用GDI+生成图像:

var fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile(Server.MapPath("~/fonts/abraham-webfont.ttf"));
fontCollection.Families.Count(); // => This line tells me, that the collection has 0 items.
没有异常,但在
AddFontFile
方法运行后,fontCollection Families属性为空,没有任何异常

我已验证路径是否有效(
File.Exists
返回
true
):

当我打开该文件时,TTF文件似乎工作正常,因此它不是无效的TTF文件:


有什么建议吗?

汉斯·帕桑的回答解决了问题:


PrivateFontCollection是出了名的片状。一种常见的失败模式是字体实际上是带有TrueType轮廓的OpenType字体。GDI+只支持“纯”的。鞋子合脚,网络上说Abraham是一种OpenType字体。在WPF中工作,而不是在Winforms中。

您是在本地主机上还是在具有其他路径的stage/production env上工作?PrivateFontCollection是出了名的片状。一种常见的失败模式是字体实际上是带有TrueType轮廓的OpenType字体。GDI+只支持“纯”的。鞋子合脚,网络上说Abraham是一种OpenType字体。在WPF中工作,而不是在Winforms中。@HansPassant谢谢!请将此评论作为答复提交,以便我可以接受。问题在于字体,而不是代码。你现在肯定可以自己完成Q+A了吧?你不需要我的帮助。
Response.Write(System.IO.File.Exists(Server.MapPath("~/fonts/abraham-webfont.ttf"))); // # => Renders "True"