加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在Web应用程序中管理自定义字体(system.drawing)

发布时间:2020-12-15 18:17:03 所属栏目:百科 来源:网络整理
导读:我有一个应用程序使用System.Drawing(C#)将文本写入图像. 我使用特定字体来执行此操作. 由于我不能依赖我的共享托管服务器来获得我可能需要的所有自定义字体(并且由于字体列表可能会增长),我如何管理用于我的应用程序的字体? 我可以在项目中包含.ttf文件并
我有一个应用程序使用System.Drawing(C#)将文本写入图像.

我使用特定字体来执行此操作.

由于我不能依赖我的共享托管服务器来获得我可能需要的所有自定义字体(并且由于字体列表可能会增长),我如何管理用于我的应用程序的字体?

我可以在项目中包含.ttf文件并以某种方式引用它们吗?

包含字体的SQL数据库怎么样?

解决方法

应该可以将字体文件存储在磁盘或数据库中,然后使用 PrivateFontCollection类在运行时使用字体.

以下是如何使用它:

PrivateFontCollection collection = new PrivateFontCollection();
    // Add the custom font families. 
    // (Alternatively use AddMemoryFont if you have the font in memory,retrieved from a database).
    collection.AddFontFile(@"E:Downloadsactest.ttf");
    using (var g = Graphics.FromImage(bm))
    {
        // Create a font instance based on one of the font families in the PrivateFontCollection
        Font f = new Font(collection.Families.First(),16);
        g.DrawString("Hello fonts",f,Brushes.White,50,50);
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读