如何用C#生成条形码?

只需要含有产品序号就可以了
2024-12-27 03:44:59
推荐回答(3个)
回答1:

代码如下:

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();}

回答2:

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();}

回答3:

添加spire.barcode.dll为引用,有38+的条码类型可选,下面以Code 39条码为例:

  1. BarcodeSettings bs = new BarcodeSettings();

  2. bs.Type = BarCodeType.Code39;

  3. bs.Data = "*ABC 12345* ";              

  4. BarCodeGenerator bg = new BarCodeGenerator(bs);

  5. bg.GenerateImage().Save("Code39Code.png");