生成条码

using System;

using  System.Drawing;
using  ZXing.QrCode;
using  ZXing;
using  ZXing.Common;
 
 
namespace  NKO_Printer_Core
{
     public  class  BarcodeHelper
     {
         ///
         /// 返回生成的Bitmap对象
         ///
         /// 条码内容
         /// 条码格式
         /// 条码高度
         /// 宽度高度
         ///
         public  static  Bitmap CreateBarcode( string  barcodeContent,BarcodeFormat barcodeFormat, int  height, int  width)
         {
             try
             {
                 BarcodeWriter writer =  new  BarcodeWriter();
                 EncodingOptions options =  new  QrCodeEncodingOptions
                 {
                     DisableECI =  true ,
                     CharacterSet =  "UTF-8" ,
                     Width = height,
                     Height = width
                 };
                 writer.Options = options;
                 writer.Format = barcodeFormat;
                 return  writer.Write(barcodeContent);
                
             }
             catch  (Exception e)
             {
                 return  null ;
             }
         }
     }
}
 

System.Drawing.Bitmap img = CreateBarcode("123456", BarcodeFormat.CODE_39,30,120);
img.Save("d:/1.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);

转载于:https://www.cnblogs.com/zhang-wenbin/p/7469065.html

你可能感兴趣的:(生成条码)