Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从“我的解决方案资源”文件夹到字体的字节数组_C#_.net_Fonts - Fatal编程技术网

C# 从“我的解决方案资源”文件夹到字体的字节数组

C# 从“我的解决方案资源”文件夹到字体的字节数组,c#,.net,fonts,C#,.net,Fonts,我想使用的资源文件夹中有特定的字体 Label label; label.FontFamily=MyNamespace.Properties.Resources. 我可以看到我的Font名称,但返回的是Byte[]。 如何将其用作Font?尝试此功能 private System.Drawing.Font GetFontFromResource() { Stream fontStream = this.GetType().Assembly.GetManifestResourceStream(

我想使用的
资源
文件夹中有特定的
字体

Label label;
label.FontFamily=MyNamespace.Properties.Resources.
我可以看到我的
Font
名称,但返回的是
Byte[]
。 如何将其用作
Font

尝试此功能

private System.Drawing.Font GetFontFromResource()
{
 Stream fontStream = this.GetType().Assembly.GetManifestResourceStream("yourfont.ttf");

      byte[] fontdata = new byte[fontStream.Length];
      fontStream.Read(fontdata,0,(int)fontStream.Length);
      fontStream.Close();
      unsafe
      {
        fixed(byte * pFontData = fontdata)
        {
          return new  System.Drawing.Font((System.IntPtr)pFontData, 16, FontStyle.Regular);
        }
      }
}
如何从程序集加载资源:(
YourNamespace.file.ttf
):

我不想加载字体,但只想从资源文件夹加载字体确定,它从资源文件夹加载字体并将其转换为
font
。然后您可以将其用于
标签。Font
:)清楚吗?但是我应该在“yourfont.ttf”里面写什么呢?只有字体名?@markyer,您可以编写
MyNamespace.Properties.Resources.yourfont.ttf
:)。