我正在生成IDAutomationHC39M条形码,但在生成和扫描后,我没有得到任何值。
我的代码是
public void generateBarcode(int id)
{
if (plBarCode != null)
{
string barCode = "";
barCode = "*"+Convert.ToString(id)+"*";
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
using (Bitmap bitMap = new Bitmap(barCode.Length * 70, 70))
{
using (Graphics graphics = Graphics.FromImage(bitMap))
{
Font oFont = new Font("IDAutomationHC39M", 30);
PointF point = new PointF(2f, 2f);
SolidBrush blackBrush = new SolidBrush(Color.Black);
SolidBrush whiteBrush = new SolidBrush(Color.White);
graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
int w = barCode.Length * 40;
Graphics oGraphics = Graphics.FromImage(bitMap);
PointF oPoint = new PointF(2f, 2f);
SolidBrush oBrushWrite = new SolidBrush(Color.Black);
SolidBrush oBrush = new SolidBrush(Color.White);
oGraphics.FillRectangle(oBrush, 0, 0, w, 100);
oGraphics.DrawString("*" + barCode + "*", oFont, oBrushWrite, oPoint);
}
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);
}
plBarCode.Controls.Add(imgBarCode);
}
}
}
这段代码有什么不对。
我应该如何生成代码?
答案 0 :(得分:0)
以下是条形码字体无法扫描的前5个原因......
http://idautomation.blogspot.in/2011/07/top-5-reasons-why-barcode-font-wont.html
如果您尝试对少量字符进行编码,最好确保您的扫描仪能够扫描最小量,因为许多设置为在条形码中读取至少4个字符。另一方面,如果在条形码中编码的字符太多,则它将太大并且将无法正确扫描。减小字体大小并重新扫描可能会解决此问题。