如何管理Web应用程序自定义字体(System.Drawing中) [英] How to manage custom fonts in web application (system.drawing)
问题描述
我有写上文字使用System.Drawing中(C#)图像的应用程序。我使用特定的字体来做到这一点。既然不能靠我的共享托管服务器拥有所有我需要的自定义字体(并且字体列表可能会增长),我怎么能管理用于我的应用程序的字体?我可以在自己的项目的.ttf文件,并以某种方式引用它们?约含字体的SQL数据库怎么办?
I have an application that writes text onto images using system.drawing (C#). I am using specific fonts to do this. Since I can't rely on my shared hosting servers to have all the custom fonts I may need (and since the list of fonts is likely to grow), how can I manage the fonts used for my application? Could I include .ttf files in my project and reference them somehow? What about a SQL database containing fonts?
推荐答案
这应该有可能您的字体文件存储在磁盘或数据库,然后使用 PrivateFontCollection 类在运行时使用的字体。
It should be possible to store your font files on disk or in database, and then use the PrivateFontCollection class to use the fonts at runtime.
下面是你将如何使用它:
Here is how you would use it:
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);
}
这篇关于如何管理Web应用程序自定义字体(System.Drawing中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!