[英]How to extract Excel rows from uploaded Base64String into List<Object>
[英]How to deserialize an uploaded font from a Base64String?
我需要從上傳的字體中獲取字體系列名稱。 用戶上傳一個.ttf文件。 當我嘗試反序列化數據時,出現以下錯誤“輸入流不是有效的二進制格式”。 字體數據使用readAsDataURL()通過HTML5 FileReader上載。
誰能發現我在做什么錯? 我懷疑我使用了錯誤的反序列化器...但是我不確定。
//clean the font data of encoding
var cleanFontData = brandingsFontAddViewModel.FontData.Split(',')[1];
var fontBytes = Convert.FromBase64String(cleanFontData);
using (Stream memStream = new MemoryStream(fontBytes, 0, fontBytes.Length))
{
var deserializer = new BinaryFormatter();
var font = (Font)deserializer.Deserialize(memStream);
}
終於找到答案了。
// used to store our font and make it available in our app
var pfc = new PrivateFontCollection();
IntPtr data = Marshal.AllocCoTaskMem((int) ms.Length);
Marshal.Copy(fontBytes, 0, data, (int)ms.Length);
pfc.AddMemoryFont(data, (int)ms.Length);
Marshal.FreeCoTaskMem(data);
var fontWithMime = "data:application/x-font-truetype;charset=utf-8;base64," + cleanFontData;
fontName = pfc.Families[0].Name;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.