C#使用Zxing.dll組件解析二維碼的實(shí)現(xiàn)
1.首先下載Zxing.dll組件,將dll組件放置debug文件夾中,引用參考,引入空間命名。

2.解碼方法
string result = string.Empty;
//--解碼
private string RQDecode(Bitmap img)
{
string errText = string.Empty;
Result result = null;
if (img != null)
{
try
{
result = new BarcodeReader().Decode(new Bitmap(pictureBox1.Image));
string barCodeStr = result.ToString();
labelBarCodeResult.Text = "識(shí)別結(jié)果是:" + barCodeStr;
//listBox1.Items.Add(barCodeStr);
}
catch { return errText; }
if (result != null)
{
return result.Text;
}
else
{
return errText;
}
}
else
{
return errText;
}
}3.全部源碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZXing;
namespace Code_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string pathname = string.Empty;//定義路徑名變量
private void button1_Click(object sender, EventArgs e)
{
DialogOperate openfile = new DialogOperate();//實(shí)例化對(duì)象
textBox1.Text = openfile.OpenFile();//調(diào)用方法,顯示圖片路徑
pathname = textBox1.Text;//獲取文件路徑
if (pathname != string.Empty)//這個(gè)判斷用處不大
{
try
{
this.pictureBox1.Load(pathname);//加載圖片路徑
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
string result = string.Empty;
//--解碼
private string RQDecode(Bitmap img)
{
string errText = string.Empty;
Result result = null;
if (img != null)
{
try
{
result = new BarcodeReader().Decode(new Bitmap(pictureBox1.Image));
string barCodeStr = result.ToString();
labelBarCodeResult.Text = "識(shí)別結(jié)果是:" + barCodeStr;
//listBox1.Items.Add(barCodeStr);
}
catch { return errText; }
if (result != null)
{
return result.Text;
}
else
{
return errText;
}
}
else
{
return errText;
}
}
private void button2_Click(object sender, EventArgs e)
{
RQDecode(new Bitmap(pictureBox1.Image));//開(kāi)始解析
}
}
}4.效果圖

到此這篇關(guān)于C#使用Zxing.dll組件解析二維碼的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)C# Zxing.dll解析二維碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- C#使用zxing/zbar/thoughtworkQRcode解析二維碼的示例代碼
- C# 如何生成 DataMatrix 格式的二維碼
- c# 生成二維碼的示例
- C# 根據(jù)字符串生成二維碼的實(shí)例代碼
- C#實(shí)現(xiàn)掃描槍掃描二維碼并打印(實(shí)例代碼)
- C#基于QRCode實(shí)現(xiàn)動(dòng)態(tài)生成自定義二維碼圖片功能示例
- C#生成帶二維碼的專屬微信公眾號(hào)推廣海報(bào)實(shí)例代碼
- C#二維碼圖片識(shí)別代碼
- C#利用ZXing.Net生成條形碼和二維碼
- C# TSC打印二維碼和條形碼的實(shí)現(xiàn)方法
- C#生成帶logo的二維碼
相關(guān)文章
unity實(shí)現(xiàn)動(dòng)態(tài)排行榜
這篇文章主要為大家詳細(xì)介紹了unity實(shí)現(xiàn)動(dòng)態(tài)排行榜,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07
C# TcpClient網(wǎng)絡(luò)編程傳輸文件的示例
這篇文章主要介紹了C# TcpClient網(wǎng)絡(luò)編程傳輸文件的示例,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-04-04
C# 中將數(shù)值型數(shù)據(jù)轉(zhuǎn)換為字節(jié)數(shù)組的方法
C# 中將數(shù)值型數(shù)據(jù)轉(zhuǎn)換為字節(jié)數(shù)組的方法,需要的朋友可以參考一下2013-05-05
C#中神器類BlockingCollection的實(shí)現(xiàn)詳解
如果你想玩轉(zhuǎn)C#?里面多線程,工廠模式,生產(chǎn)者/消費(fèi)者,隊(duì)列等高級(jí)操作,就可以和我一起探索這個(gè)強(qiáng)大的線程安全提供阻塞和限制功能的C#神器類BlockingCollection吧2023-02-02

