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に正しく挿入されていますが、印刷してバーコードをスキャンするとスキャンされません。
Web から同様のバーコードをオンラインで作成し、印刷物を取り、完全にスキャンされたため、スキャナーとその動作を確認しました。
私が確認できる唯一の違いは、オンラインで生成されたバーコードと私のアプリケーションの視覚的な外観です。オンライン バーコードに印刷された線はよりしっかりしていますが、私のアプリケーションから生成されたバーコードにはかすんだ線があります。これが原因であるかどうかはわかりません。
私はこれについてここ数日から苦労しています。お知らせ下さい。