代码如下:
Visual C# .NETprivate void SaveBarcode(){ //Create a Barcode Professional object Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings bcp.BarHeight = 1.0f; bcp.BarWidth = 0.01f; //Resolution float dpi = 300.0f; //Target size in inches System.Drawing.SizeF targetArea = new System.Drawing.SizeF(1.0f, 0.5f); //Get the barcode image fitting the target area System.Drawing.Image imgBarcode = bcp.GetBarcodeImage(dpi, targetArea); //Save it on disk in PNG format imgBarcode.Save(@"C:\temp\barcode128.png", System.Drawing.Imaging.ImageFormat.Png); imgBarcode.Dispose();}
Visual C# .NETprivate void SaveBarcode(){ //Create a Barcode Professional object Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings bcp.BarHeight = 1.0f; bcp.BarWidth = 0.01f; //Resolution float dpi = 300.0f; //Target size in inches System.Drawing.SizeF targetArea = new System.Drawing.SizeF(1.0f, 0.5f); //Get the barcode image fitting the target area System.Drawing.Image imgBarcode = bcp.GetBarcodeImage(dpi, targetArea); //Save it on disk in PNG format imgBarcode.Save(@"C:\temp\barcode128.png", System.Drawing.Imaging.ImageFormat.Png); imgBarcode.Dispose();}
添加spire.barcode.dll为引用,有38+的条码类型可选,下面以Code 39条码为例:
BarcodeSettings bs = new BarcodeSettings();
bs.Type = BarCodeType.Code39;
bs.Data = "*ABC 12345* ";
BarCodeGenerator bg = new BarCodeGenerator(bs);
bg.GenerateImage().Save("Code39Code.png");