public class Barcode
{
public Bitmap CreateBarcode(string data)
{
string barcodeData = "*" + data + "*";
Bitmap barcode = new Bitmap(1, 1);
// less than size 40, my barcode reader can not read it.
Font threeOfNine = new Font("Free 3 of 9", 40,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point);
Font arial = new Font("Arial", 15,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point);
Graphics graphics = Graphics.FromImage(barcode);
SizeF dataSize = graphics.MeasureString(barcodeData, threeOfNine);
dataSize.Height = 70;
barcode = new Bitmap(barcode, dataSize.ToSize());
graphics = Graphics.FromImage(barcode);
graphics.Clear(Color.White);
graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
graphics.DrawString(barcodeData, threeOfNine, new SolidBrush(Color.Black), 0, 0);
graphics.DrawString(data, arial, new SolidBrush(Color.Black), 50, 40);
graphics.Flush();
threeOfNine.Dispose();
graphics.Dispose();
return barcode;
}
}
我正在使用上面的代码使用 Free 3 of 9 生成条形码。但如果我看到小于 40 的尺寸,我的条形码阅读器无法读取该代码。40 码对我的应用来说太大了,有什么办法可以减小条码的大小吗?
Font threeOfNine = new Font("Free 3 of 9", 30,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point);