当前位置:网站首页>winform使用zxing生成二维码
winform使用zxing生成二维码
2022-06-29 09:26:00 【zlbcdn】
之前只使用了条形码,使用的是字体库。今儿上午在网上看到一个生成二维码的,顺手试了试,很简单。
ZXing是一个通过Java实现的开源类库,主要的目的就是生成/解析各种各样的条码,其支持的编码方式如下:

其支持的编码方式还是比较多的。
另外,在网上找到的ZXing的Demo大多是Java编写的,所以也顺手记一下winform下的实现。
1、效果


2、具体操作
3、代码分析
private void button1_Click(object sender, EventArgs e)
{
try
{
//生成条码的核心类,具体相关方法可查找方法说明
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,//编码类型(枚举类型)
Options = new ZXing.Common.EncodingOptions
{
//设定条码的大小
Width=210,
Height=210
},
//BitMatrix
Renderer = (ZXing.Rendering.IBarcodeRenderer<Bitmap>)Activator.CreateInstance(Renderer)
};
//将内容生成QR码,并展示在pictureBox上
//至于接下来是保存到本地还是直接使用,取决于实际需求
this.pictureBox1.Image = writer.Write(this.textBox1.Text);
}
catch (Exception exc)
{
MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}4、源码下载
边栏推荐
- We can't tell the difference between distributed and cluster. Let's tell the story of two cooks cooking
- Codeforces Round #657 Div. 2
- sympy的dsolve函数
- Power strings [KMP cycle section]
- Slide the custom control to close the activity control
- Minorgc, majorgc, fullgc
- Serpentine filling number
- Nacos环境隔离
- 基辅周边的凄美废墟——切尔诺贝利的安全前往指南!
- To 3 --- 最后的编程挑战
猜你喜欢
随机推荐
点在多边形内外的判断
Is flush stock trading software reliable and safe?
任务调度器之Azkaban的使用
Codeforces Round #659 (Div. 2)
2019.10.6 training summary
【51nod 1215】数组的宽度
HDU 6778 car (group enumeration -- > shape pressure DP)
Power strings [KMP cycle section]
Wandering --- 最后的编程挑战
JVM instructions for four call methods
2020-9-14 introduction to advertising system
Six dimensional space BFS
Slide the custom control to close the activity control
Time varying and non time varying
C语言库函数--strstr()
Use of Azkaban in task scheduler
2020-09-21 visual studio header file and Library Directory configuration
使用Rancher搭建Kubernetes集群
Beautiful ruins around Kiev -- a safe guide to Chernobyl!
2019.11.17 training summary









