c#生成條形碼


一、生成EAN13的一維碼
// 1.設置條形碼規格
EncodingOptions encodeOption = new EncodingOptions();
encodeOption.Height = 130; // 必須制定高度、寬度
encodeOption.Width = 240;
 
// 2.生成條形碼圖片並保存
ZXing.BarcodeWriter wr = new BarcodeWriter();
wr.Options = encodeOption;
wr.Format = BarcodeFormat.EAN_13; //  條形碼規格:EAN13規格:12(無校驗位)或13位數字
Bitmap img = wr.Write( this .ContentTxt.Text); // 生成圖片
string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "\\EAN_13-" + this .ContentTxt.Text + ".jpg" ;
img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
 二、讀取一維碼
// 1.設置讀取條形碼規格
DecodingOptions decodeOption = new DecodingOptions();
decodeOption.PossibleFormats = new List<BarcodeFormat>() {
    BarcodeFormat.EAN_13,
};
 
// 2.進行讀取操作
ZXing.BarcodeReader br = new BarcodeReader();
br.Options = decodeOption;
ZXing.Result rs = br.Decode( this .barCodeImg.Image as Bitmap);
if (rs == null )
{
     this .ContentTxt.Text = "讀取失敗" ;
     MessageBox.Show( "讀取失敗" );
}
else
{
     this .ContentTxt.Text = rs.Text;
     MessageBox.Show( "讀取成功,內容:" + rs.Text);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM