C# 获取ttf文件字体名称

1、第一种方法

using System.Windows.Media;

String fontFilePath = "PATH TO YOUR FONT";
GlyphTypeface glyphTypeface = new GlyphTypeface(fontFileURI);
String fontFamily = glyphTypeface.Win32FamilyNames[new System.Globalization.CultureInfo("en-us")];
String fontFace = glyphTypeface.Win32FaceNames[new System.Globalization.CultureInfo("en-us")]; Console.WriteLine("Font: " + fontFamily + " " + fontFace);
2、第二种方法
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Runtime.InteropServices; namespace Utility
{
public class Font
{
public string GetFont(byte[] [FONTASBYTEARRAY])
{
PrivateFontCollection fc = new PrivateFontCollection();
IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement([FONTASBYTEARRAY], 0);
fc.AddMemoryFont(pointer, Convert.ToInt32([FONTASBYTEARRAY].Length));
System.Drawing.Font f = new System.Drawing.Font(fc.Families[0], 10);
FontFamily ff = f.FontFamily;
return ff.Name;
}
}
}
上一篇:bootstrap的datetimepicker只选择月份


下一篇:javascript学习教程之---如何从一个tab切换到banner幻灯片的转换