C#客户端打印条形码

0
6

第一种方法:
引用第三方插件文件zxing.dll

 1 // 1.设置条形码规格
 2             EncodingOptions encodeOption = new EncodingOptions();
 3             encodeOption.Height = 160; // 必须制定高度、宽度
 4             encodeOption.Width = 60;
 5             encodeOption.Margin = 1;
 6             encodeOption.PureBarcode = true;
 7 
 8             // 2.生成条形码图片并保存
 9             ZXing.BarcodeWriter wr = new BarcodeWriter();
10             wr.Options = encodeOption;
11             wr.Format = BarcodeFormat.CODE_128;  // 这里可以设定条码的标准
12             Bitmap img = wr.Write("20186900012000010001"); // 生成图片
13             string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "..\\CODE_131.jpg";
14             img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);

第二种方法:
引用第三方插件库文件BarcodeLib.dll和BarCode.dll文件

  //竖型条形码
            BarcodeLib.Barcode barcode = new BarcodeLib.Barcode();
            barcode.Alignment = BarcodeLib.AlignmentPositions.CENTER;
            barcode.Width = 150;
            barcode.Height = 40;
            barcode.RotateFlipType = RotateFlipType.Rotate90FlipNone;
            barcode.BackColor = Color.White;
            barcode.ForeColor = Color.Black;
            string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "..\\CODE.jpg";
            Image img = barcode.Encode(BarcodeLib.TYPE.CODE128, "20186900012000010002");
            img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
             
             //条形码
            BarcodeLib.Barcode barcode_2 = new BarcodeLib.Barcode();
            barcode_2.Alignment = BarcodeLib.AlignmentPositions.CENTER;
            barcode_2.Width = 160;
            barcode_2.Height = 60;
            barcode_2.RotateFlipType = RotateFlipType.RotateNoneFlipNone;
            barcode_2.BackColor = Color.White;
            barcode_2.ForeColor = Color.Black;
            string filePath_2 = System.AppDomain.CurrentDomain.BaseDirectory + "..\\CODE_2.jpg";
            Image img_2 = barcode_2.Encode(BarcodeLib.TYPE.CODE128, "20186900012000010001");
            img_2.Save(filePath_2, System.Drawing.Imaging.ImageFormat.Jpeg);

<

发布回复

请输入评论!
请输入你的名字