【问题标题】:Not getting value after scanning the barcode IDAutomationHC39M扫描条码 IDAutomationHC39M 后未获得价值
【发布时间】:2018-02-12 22:38:19
【问题描述】:

我正在生成 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);
            }
        }

    }

这段代码有什么问题。

我应该如何生成我的代码?

【问题讨论】:

  • 您当前的代码会生成一个条形码,每边都有 两个 *。从oGraphics.DrawString() 函数调用中删除额外的"*"
  • 同样在删除 * 之后它也没有生成
  • @Cᴏʀʏ 你的意思是 barCode = " ** "+Convert.ToString(id)+" ** ";像这样?
  • 否,在包含oGraphics.DrawString("*"+barCode+"*", ...); 的行中。你已经用*包围了ID,你不需要在该行再做一次。
  • @Cᴏʀʏ 是的,但在移除 * 之后,即通过 barCode =Convert.ToString(id);我无法生成实际的条形码

标签: c# asp.net barcode


【解决方案1】:

这是条码字体无法扫描的 5 大原因 ...

http://idautomation.blogspot.in/2011/07/top-5-reasons-why-barcode-font-wont.html

如果您尝试对少量字符进行编码,最好确保您的扫描仪能够扫描最少数量的字符,因为许多设置为读取条码中至少 4 个字符。另一方面,如果条码中编码的字符太多,则它会太大而无法正确扫描。减小字体大小并重新扫描可能会解决此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    相关资源
    最近更新 更多