c#生成条形码
2021-05-08 21:27
标签:coder app basedir odi bar domain nts string iter c#生成条形码 标签:coder app basedir odi bar domain nts string iter 原文地址:http://www.cnblogs.com/yuanlaohou/p/7623634.html// 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.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);
}