簡體   English   中英

Xamarin.Forms 無法轉換 stream 中的 TTF 文件

[英]Xamarin.Forms can't convert TTF file in stream

I'm working on Xamarin.Forms app with help of Syncfusion and want to add Cyrillic support in PDF drawing.I download ArialUnicodeMS.tff added the file in Shared Project in Resources folder and added Build Action Embedded Resource and also added [assembly: ExportFont("ArialUnicodeMS.ttf", Alias = "ArialUni")]AssemblyInfo.cs中。 但是 Syncfusion Pdf 繪圖想要通過Stream訪問 TTF 文件。

這是我的代碼:

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(EmbeddedFont)).Assembly;
Stream stream = assembly.GetManifestResourceStream("MyAppName.ArialUnicodeMS.ttf");
PdfFont font = new PdfTrueTypeFont(stream, 14);

但我的字符串總是null 我哪里錯了?

資源丟失。

很可能是以下三個問題之一:

  • 名稱"MyAppName.ArialUnicodeMS.ttf"有錯字。
  • 資源未嵌入typeof(EmbeddedFont)).Assembly程序集中。
  • 您尚未將參數Build Action設置為Embedded Resource 這是EmbeddedFont項目的一部分,作用於ArialUnicodeMS.ttf資源。

要驗證哪些名稱可用,您可以使用:

string resourceNames = assembly.GetManifestResourceNames();

您可以使用下面的代碼從嵌入式資源中獲取 stream。

   var assembly = Assembly.GetExecutingAssembly();
        var resourceName = "App28.Trashtalk.ttf";
        Stream stream = assembly.GetManifestResourceStream(resourceName);

暫無
暫無

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

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