我使用以下代码将字体加载到内存中,以便使用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.没有异常,但是fontCollection系列属性在AddFontFile方法运行后为空,没有任何异常。
我已经验证了路径是有效的(File.Exists返回true):
Response.Write(System.IO.File.Exists(Server.MapPath("~/fonts/abraham-webfont.ttf"))); // # => Renders "True"当我打开文件时,TTF-文件似乎工作得很好,所以它不是无效的TTF-文件:

有什么建议吗?
发布于 2016-10-13 12:37:33
汉斯·帕桑特的回答解决了这个问题:
PrivateFontCollection是出了名的懒散。今天非常常见的一种失败模式是,字体实际上是带有OpenType轮廓的TrueType字体。GDI+只支持“纯”的。这双鞋很合身,网站上说亚伯拉罕是OpenType字体。在WPF工作,而不是在Winforms。
https://stackoverflow.com/questions/40008150
复制相似问题