ZXing.net抛出系统.Font 'Arial'不支持'Regular'错误
本文关键字:Arial 不支持 Regular 错误 net 系统 Font ZXing | 更新日期: 2023-09-27 18:08:02
当执行使用ZXing.net创建条形码的asp.net页面时,它在Windows 10计算机上工作良好,但在Windows 2012服务器上不行。在服务器上抛出以下错误:
代码:
Image imgBarCode = new Image();
var codabar = new ZXing.BarcodeWriter();
codabar.Options = options;
codabar.Format = ZXing.BarcodeFormat.CODE_128;
using (Bitmap bitMap = new Bitmap(codabar.Write(customerID.Trim())))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
imgBarCode.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(byteImage);
}
panelGeneralInfo.Controls.Add(imgBarCode);
}
ZXing.Rendering的类型初始化器。BitmapRenderer'抛出了一个异常。
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. --->
System.TypeInitializationException: The type initializer for 'ZXing.Rendering.BitmapRenderer' threw an exception. --->
System.ArgumentException: Font 'Arial' does not support style 'Regular'.
at System.Drawing.Font.CreateNativeFont()
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font.Initialize(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style)
at ZXing.Rendering.BitmapRenderer..cctor() in C:'ZXing.Net.0.14.0.0'Source'lib'renderer'BitmapRenderer.cs:line 56 --- End of inner exception stack trace ---
at ZXing.Rendering.BitmapRenderer..ctor() in C:'ZXing.Net.0.14.0.0'Source'lib'renderer'BitmapRenderer.cs:line 65
at ZXing.BarcodeWriter..ctor() in C:'ZXing.Net.0.14.0.0'Source'lib'BarcodeWriter.cs:line 112
重新启动IIS已解决此问题。显然,.net框架创建的堆栈跟踪是一种误导!