抄袭自:https://www.cnblogs.com/y114113/p/6256244.html
步骤:
1 利用NuGet下载ZXing.Net,
地址:https://www.nuget.org/packages/ZXing.Net/0.16.4
利用NuGet下载ZXing.Net可以参考:
NuGet使用教程(gif动态图的方式演示):https://blog.youkuaiyun.com/zxy13826134783/article/details/85336968
NuGet学习笔记(1)——初识NuGet及快速安装使用:
https://kb.cnblogs.com/page/143190/
VS使用Nuget教程详解 Visual studio 安装第三方的组件库:https://www.cnblogs.com/dathlin/p/7705014.html
VS2013中Nuget程序包管理器控制台使用入门:http://www.cnblogs.com/wangqiideal/p/4672329.html
我下载的版本是0.10.0,不行的话就多试几个版本,如下图:
2 编写代码:
winform主界面如下图,因为只是测试嘛,所有就弄得简单点。
要解析的二维码,把它下载然后拷贝到工程的Debug目录(图片保存名称为test.png)下,如下图:
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO; //添加的命名空间
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZXing; //添加的命名空间
namespace 二维码解析
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDecode_Click(object sender, EventArgs e)
{
//二维码图片的路径,为了简单点就放在Debug目录下了
string path = "test.png";
FileStream fs=new FileStream(path,FileMode.Open);
Bitmap bitmap = Bitmap.FromStream(fs) as Bitmap;
BarcodeReader reader = new BarcodeReader();
Result result=reader.Decode(bitmap);
string resultText=result.Text;
txtResult.Text = resultText;
}
}
}
运行结果如下图: