为IDAutomationHC39M创建2位条形码,但不扫描 [英] Create 2 digit barcode for IDAutomationHC39M but not scanning

查看:156
本文介绍了为IDAutomationHC39M创建2位条形码,但不扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为编号50或51生成IDAutomationHC39M,但已生成该条形码,但在扫描时我无法获得该编号的详细信息.

I am trying to generating IDAutomationHC39M for number 50 or 51 the barcode for that gets generated but on scanning I am not able to get the Detail number for that.

以同样的方式,我可以为14757创建条形码,在这种情况下,我可以正确扫描该条形码.

我应如何扫描生成的2位数条形码.

在下面的代码中是否有我做错的事情.

Is there some thing I am doing wrong in below code.

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);
            }
        }

    }

生成下面的条形码,编号为56,并且还在扫描时从传递的字符串中删除了*,但未返回数据56.

Generated the below barcode with number 56 and also removed * from the passing string still on scanning not returning the data 56.

推荐答案

使用此修改后的代码.

public void generateBarcode(string id)
{
                int w = id.Length * 55;

                // Create a bitmap object of the width that we calculated and height of 100
                Bitmap oBitmap = new Bitmap(w, 100);
                // then create a Graphic object for the bitmap we just created.
                Graphics oGraphics = Graphics.FromImage(oBitmap);
                // Now create a Font object for the Barcode Font
                // (in this case the IDAutomationHC39M) of 18 point size
                Font oFont = new Font("IDAutomationHC39M", 18);
                // Let's create the Point and Brushes for the barcode
                PointF oPoint = new PointF(2f, 2f);
                SolidBrush oBrushWrite = new SolidBrush(Color.Black);
                SolidBrush oBrush = new SolidBrush(Color.White);
                // Now lets create the actual barcode image
                // with a rectangle filled with white color
                oGraphics.FillRectangle(oBrush, 0, 0, w, 100);
                // We have to put prefix and sufix of an asterisk (*),
                // in order to be a valid barcode
                oGraphics.DrawString("*" + id + "*", oFont, oBrushWrite, oPoint);
                // Then we send the Graphics with the actual barcode
                System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();

                using (System.IO.FileStream fs = System.IO.File.Open(Server.MapPath("~/img/barcodes/") + id + ".jpg", FileMode.Create))
                {
                    oBitmap.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);

                }
                oBitmap.Dispose();
                imgbarcode.ImageUrl = "~/img/barcodes/"+id+".jpg";
}

这篇关于为IDAutomationHC39M创建2位条形码,但不扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆