我有一个 asp.net 网站,我想用 c# 打印一些条形码。我使用“IDAutomationHC39M”字体如下:
public static void PrintSmallBarcode(HtmlGenericControl divBarCode, string barCode)
{
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
using (Bitmap bitMap = new Bitmap(75, 18))
{
using (Graphics graphics = Graphics.FromImage(bitMap))
{
Font oFont = new Font("IDAutomationHC39M", 7);
PointF point = new PointF(0, 0);
SolidBrush blackBrush = new SolidBrush(Color.Black);
SolidBrush whiteBrush = new SolidBrush(Color.White);
graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
graphics.DrawString(barCode, oFont, blackBrush, point);
}
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
Convert.ToBase64String(byteImage);
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
imgBarCode.CssClass = "cssbarcode";
}
}
div.Controls.Add(imgBarCode);
}
它可以工作,但是条码的质量很低,我的条码阅读器设备无法读取它。我不能增加图像的大小,当然我看到很多比我的尺寸小的好的条形码。我用“free3of9.ttf”替换“IDAutomationHC39M”字体,但这个字体只画数字,没有条码线!我怎样才能获得更好的条形码?