C#生成条形码
轉(zhuǎn)自:http://www.cnblogs.com/AspDotNetMVC/archive/2012/11/16/2767576.html
1 static byte[] GetBarcode(int height, int width,BarcodeLib.TYPE type, 2 string code,out System.Drawing.Image image) 3 { 4 image=null; 5 BarcodeLib.Barcode b = new BarcodeLib.Barcode(); 6 b.BackColor = System.Drawing.Color.White; 7 b.ForeColor = System.Drawing.Color.Black; 8 b.IncludeLabel = true; 9 b.Alignment = BarcodeLib.AlignmentPositions.CENTER; 10 b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; 11 b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; 12 System.Drawing.Font font = new System.Drawing.Font("verdana",10f); 13 b.LabelFont = font; 14 15 b.Height = height; 16 b.Width = width; 17 18 image = b.Encode(type, code); 19 SaveImage(image, Guid.NewGuid().ToString("N")+".png"); 20 byte[] buffer = b.GetImageData(SaveTypes.GIF); 21 return buffer; 22 }原博主的代碼沒有貼出保存圖片的代碼,現(xiàn)在加上
static void BuildBarcode(){System.Drawing.Image image;int width=250, height=100;byte[] buffer = GetBarcode(height, width, BarcodeLib.TYPE.CODE128, "Avx-(13614)-vR", out image);}?
1 static byte[] GetBarcode(int height, int width,BarcodeLib.TYPE type, 2 string code,out System.Drawing.Image image) 3 { 4 image=null; 5 BarcodeLib.Barcode b = new BarcodeLib.Barcode(); 6 b.BackColor = System.Drawing.Color.White; 7 b.ForeColor = System.Drawing.Color.Black; 8 b.IncludeLabel = true; 9 b.Alignment = BarcodeLib.AlignmentPositions.CENTER; 10 b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; 11 b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; 12 System.Drawing.Font font = new System.Drawing.Font("verdana",10f); 13 b.LabelFont = font; 14 15 b.Height = height; 16 b.Width = width; 17 18 image = b.Encode(type, code); 19 SaveImage(image, Guid.NewGuid().ToString("N")+".png"); 20 byte[] buffer = b.GetImageData(SaveTypes.GIF); 21 return buffer; 22 } 23 24 private static void SaveImage(System.Drawing.Image image, string p) 25 { 26 //自動(dòng)保存圖片到指定目錄中 27 string stringfilename ="G:\\" + p; 28 image.Save(stringfilename, System.Drawing.Imaging.ImageFormat.Jpeg); 29 }使用該方法還需要一個(gè)動(dòng)態(tài)鏈接庫(kù):
?
barcode.dll下載
生成的條形碼:
轉(zhuǎn)載于:https://www.cnblogs.com/robinblogs/p/4485502.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
- 上一篇: 设置360浏览器 设置360浏览器主页
- 下一篇: 怎么下载掌上生活app(word怎么打出