1

问题是我无法加载字体然后在位图中渲染。具体来说,asp.net 网页代码创建一个位图,然后尝试将文本写入位图中。我尝试将代码从一台服务器(Win 2003)移动到另一台服务器(Win 2008)。它适用于 Win 2003 但不适用于 Win 2008。我从旧服务器复制字体 (.ttf) 并将它们安装在新服务器上。

代码:

Bitmap barcode = new Bitmap(1, 1);
ffamily = new FontFamily("Free 3 of 9"); //exception

Font threeOfNine = new Font(ffamily, 60, FontStyle.Regular, GraphicsUnit.Point);
Graphics graphics = Graphics.FromImage(barcode);
SizeF size = graphics.MeasureString(number, threeOfNine);
barcode = new Bitmap(barcode, size.ToSize());
graphics = Graphics.FromImage(barcode);
graphics.Clear(Color.White);
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
graphics.DrawString(number, threeOfNine, new SolidBrush(Color.Black), 0, 0);
graphics.Flush();
threeOfNine.Dispose();
graphics.Dispose();

然后它在以下行抛出此异常new FontFamily()

Exception information: 
Exception type: ArgumentException 
Exception message: Font 'Free 3 of 9' cannot be found. 

字体已安装到 Windows 字体文件夹中。如果我尝试:

Font threeOfNine = new Font("Free 3 of 9", 60, FontStyle.Regular, GraphicsUnit.Point);

然后使用标准默认字体创建字体。是否存在安全问题?为什么我的字体无法正确加载?

4

1 回答 1

4

好吧,我自己找到了答案。

After installing the font and ensuring the right permissions were on the .ttf. I had to restart IIS. I think only the app pool was all that was needed to restart. Then it started working.

于 2012-08-11T00:44:26.600 回答