在小程序开发项目中,用到了小程序生成海报,需要字体:思源黑体。
按常规逻辑将思源黑体字体文件直接复制到windows\font 字体文件夹下面,然后引用,经过反复测试始终无效。
c#通过font引用字体无效怎么解决呢?
System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection(); //添加字体文件,可以添加多个 //web中,路径映射方式参考:System.Web.HttpContext.Current.Server.MapPath("/font/SourceHanSansCN-Medium.otf") privateFonts.AddFontFile("d:\\font\\SourceHanSansCN-Medium.otf"); System.Drawing.Font font = new Font(privateFonts.Families[0], 12);