【发布时间】:2013-03-28 23:47:23
【问题描述】:
我有一项旨在进行图像处理的服务。其中一项任务是在图像上叠加一个字符串,然后将其发送到程序并显示。
我无法在位图图像上叠加文本,有人可以帮忙吗?
我正在尝试使用:
PrivateFontCollection fonts = new PrivateFontCollection();
public static FontFamily LoadFontFamily(string fileName, out PrivateFontCollection fontCollection)
{
fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile(HostingEnvironment.ApplicationPhysicalPath + '/' + fileName);
return fontCollection.Families[0];
}
FontFamily family = LoadFontFamily("arial.ttf", out fonts);
Font font = new Font(family, 20);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawString("text", font, new SolidBrush(GetColorFromHexString(foreground)), new PointF(10F, 10F));
}
根据this page上的信息。
由于服务不知道“Arial”是什么 - 它显然失败了。我已将 .ttf 字体作为资源包含在服务中,并将构建内容设置为“始终复制”。
谢谢!
【问题讨论】:
-
你尝试过任何东西吗?
-
服务没有 GUI,所以字体没有意义。
-
我已经更新了问题。
-
服务器上是否提供 Arial 字体?
-
另外,检查这个问题:stackoverflow.com/q/544972/395718
标签: c# image-processing fonts gdi