1 static void BuildBarcode() 2 { 3 System.Drawing.Image image; 4 int width=250, height=100; 5 byte[] buffer = GetBarcode(height, width, 6 BarcodeLib.TYPE.CODE128, "Avx-(13614)-vR", out image); 7 }
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 }
生成的条形码: