首页 技术 正文
技术 2022年11月11日
0 收藏 391 点赞 3,326 浏览 931 个字

场景

zxing.dll下载

https://download.csdn.net/download/badao_liumang_qizhi/11623214

效果

Winform中使用zxing实现二维码生成(附dll下载)

Winform中使用zxing实现二维码生成(附dll下载)

实现

新建Winform程序,将上面下载的zxing.dll添加到引用。

Winform中使用zxing实现二维码生成(附dll下载)

Winform中使用zxing实现二维码生成(附dll下载)

拖拽一个按钮,双击进入其点击事件。

 private void button5_Click(object sender, EventArgs e)
{
//二维码要存储的内容
string codeString = "测试";
//生成二维码并返回Bitmap
Bitmap bitmap= ZxingHelper.CreateQRCode(codeString);
//保存图片到本地
//bitmap.Save(@"C:\Users\Administrator\Desktop\a.png");
//将Bitmap转换成Image对象
Image img = Image.FromHbitmap(bitmap.GetHbitmap());
//设置pictureBox的图片源
this.pictureBox1.Image = img; }

然后在页面上拖拽一个pictureBox用来显示照片

这里新建了一个工具类ZxingHelper,调用其CreateQRCode方法返回生成二维码的Bitmap格式。

这时如果想将其保存到本地,就使用Bitmap的Save()方法,参数是要保存的全路径。

如果想将照片显示在窗体上的pictureBox控件上,则使用Image的FromHbitmap()方法进行转换。

工具类中生成二维码的代码

public static Bitmap CreateQRCode(string asset)
{
EncodingOptions options = new QrCodeEncodingOptions
{
DisableECI = true,
//编码
CharacterSet = "UTF-8",
//宽度
Width = ,
//高度
Height =
};
BarcodeWriter writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;
return writer.Write(asset);
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,953
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,477
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,290
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,107
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,739
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,773