条码图像没有被扫描
本文关键字:扫描 图像 条码 | 更新日期: 2023-09-27 18:05:46
我已经创建了条形码标签在我的asp.net mvc应用程序。现在我在excel表格中插入该图像以打印标签。问题是条码扫描器无法读取条码。
我生成Code 39条形码如下:
string barcodeName = string.Format("{0}{1}", orderItem.StyleNumber + "-" + orderItem.Color + "-" + itemDetail.Size, ".png");
string barcode = orderItem.StyleNumber + "-" + orderItem.Color + "-" + itemDetail.Size;
//Settings for the Image
string TypeFaceName = "IDAutomationHC39M"; // this is the name of font from which your barcode is generated.
string imageLocation = HttpContext.Current.Server.MapPath("~/Bine/Assets/Barcode Images");
//The format of the image file
ImageFormat format = ImageFormat.Png;
string path = Path.Combine(HttpContext.Current.Server.MapPath("~/Bine/Assets/Barcode Images"), barcodeName);
//REFERENCING A FONT
PrivateFontCollection fnts = new PrivateFontCollection();
fnts.AddFontFile("IDAutomationHC39M.ttf");// this is the name of font from which your barcode is generated.
FontFamily fntfam = new FontFamily(TypeFaceName, fnts);
System.Drawing.Font fnt = new System.Drawing.Font(fntfam, 10);
fnts.AddFontFile("Arial.ttf");
FontFamily fntfam2 = new FontFamily("Arial", fnts);
//DRAWING THE IMAGE
int w = barcode.Length * 40;
Bitmap bmp = new Bitmap(w, 100); //Canvas size
Graphics g = Graphics.FromImage(bmp);
// 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);
// Create the actual barcode image
// with a rectangle filled with white color
g.FillRectangle(oBrush, 0, 0, w, 80);
// Put prefix and sufix of an asterisk (*),
// in order to be a valid barcode
g.DrawString("*" + barcode + "*", fnt, oBrushWrite, oPoint);
bmp.Save(path, format); //Saving the Image file
bmp.Dispose(); //Releasing all resources (Image file)
条码图像创建成功并保存在文件夹中。然后我创建一个excel表格,并插入以下图像:
string imgName = String.Format("{0}{1}", stList[x].Text + "-" + stList[x].Color + "-" + stList[x].Size, ".png");
string path = Path.Combine(HttpContext.Current.Server.MapPath("~/Bine/Assets/Barcode Images"), imgName);
Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)ws.Cells[rw+3, cl];
float Left = (float)((double)oRange.Left);
float Top = (float)((double)oRange.Top);
const float ImageWidth = 200;
const float ImageHeight = 26;
ws.Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageWidth, ImageHeight);
图像也在excel中正确插入,但当我打印出来并扫描条形码时,它没有扫描。
我已经检查了我的扫描仪,它的工作很好,因为我已经从网上创建了类似的条形码,打印输出,它们被完美地扫描了。
我能看出的唯一区别是在线生成的条形码和我的应用程序的视觉外观。在线条形码打印的线条更坚实,而我的应用程序生成的条形码线条模糊。我不确定这是不是原因。
我从过去的几天一直在这个问题上挣扎。请建议。
您的条形码可能无法读取,因为图像缩放使其模糊。你不应该在Excel中插入图像,而是应该将条形码文本放入单元格中,并将单元格字体设置为条形码字体。这将产生清晰、可读的条形码。