1
我使用以下代碼來加載字體到內存中以便與GDI +生成圖像:加載字體家庭從磁盤到PrivateFontCollection
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文件:
有什麼建議嗎?從漢斯帕桑特
你是否在本地主機或舞臺/製作環境中使用其他路徑? – Nathan
PrivateFontCollection臭名昭着。現在很常見的一種失敗模式是該字體實際上是一種帶有TrueType輪廓的OpenType字體。 GDI +只支持「純」的。鞋子適合,網絡上說亞伯拉罕是一個OpenType字體。適用於WPF,不適用於Winforms。 –
@HansPassant謝謝!請提交此評論作爲答案,以便我可以接受它。問題在於字體 - 而不是代碼。 – Martin