如何在Web应用程序中管理自定义字体(system.drawing)
应该可以将字体文件存储在磁盘或数据库中,然后使用 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:\Downloads\actest.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);
}
Run Code Online (Sandbox Code Playgroud)
干杯.
归档时间: |
|
查看次数: |
5839 次 |
最近记录: |