簡體   English   中英

如何從Base64String反序列化上載的字體?

[英]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;

如何從上傳的 Base64String 中提取 Excel 行到列表中<object><div id="text_translate"><p>我正在嘗試創建一種方法,該方法將上傳的 Excel 文件作為<strong>documentUploadModel 文件</strong>,然后將原始 Excel 中的每一行轉換為 object 的<strong>ReportRow</strong>的<strong>列表</strong>。 我不確定如何從這里開始。</p><pre> public async Task&lt;List&lt;ReportRow&gt;&gt; ProcessReport(DocumentUploadModel documentUploadModel) { var documentByteArray = Convert.FromBase64String(documentUploadModel.Base64EncodeString); }</pre><p> 我嘗試在網上查找,但在這里找不到任何似乎適合我需要的東西。 會很高興得到任何幫助。</p></div></object>

[英]How to extract Excel rows from uploaded Base64String into List<Object>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM