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

转载于:https://www.cnblogs.com/yuanlaohou/p/7623634.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值