一、首先下载 zxing.net
地址是:
然后将对应版本 .dll 拖入项目中,再引用之。
主要是用 barcodewriter、barcodereader。
二、生成二维码
.net 平台的代码始终要简单些。
qrcodeencodingoptions options = new qrcodeencodingoptions(); options.characterset = "utf-8"; options.disableeci = true; // extended channel interpretation (eci) 主要用于特殊的字符集。并不是所有的扫描器都支持这种编码。 options.errorcorrection = zxing.qrcode.internal.errorcorrectionlevel.h; // 纠错级别 options.width = 300; options.height = 300; options.margin = 1; // options.hints,更多属性,也可以在这里添加。 barcodewriter writer = new barcodewriter(); writer.format = barcodeformat.qr_code; writer.options = options; response.clear(); using (bitmap bmp = writer.write("http://www.cftea.com")) // write 具备生成、写入两个功能 { memorystream ms = new memorystream(); { bmp.save(ms, system.drawing.imaging.imageformat.png); response.contenttype = "image/png"; response.binarywrite(ms.toarray()); } } response.end();
纠错级别:
三、生成条形码
qrcodeencodingoptions options = new qrcodeencodingoptions(); options.characterset = "utf-8"; options.width = 300; options.height = 50; options.margin = 1; options.purebarcode = false; // 是否是纯码,如果为 false,则会在图片下方显示数字 barcodewriter writer = new barcodewriter(); writer.format = barcodeformat.code_128; writer.options = options; response.clear(); using (bitmap bmp = writer.write("12345678")) { memorystream ms = new memorystream(); { bmp.save(ms, system.drawing.imaging.imageformat.png); response.contenttype = "image/png"; response.binarywrite(ms.toarray()); } } response.end();
四、识别二维码、条形码
barcodereader reader = new barcodereader(); reader.options.characterset = "utf-8"; using (bitmap bmp = new bitmap("d:\\qr.png")) { result result = reader.decode(bmp); response.write(result.text); }
总结
好了,以上就是这篇文章的全部内容了,如果要改变背景颜色、画头像,可以直接在 bitmap 中画,希望本文的内容对大家的学习或者工作能带来一定的帮助
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论