C#使用Zxing.dll組件解析二維碼的實現(xiàn)
更新時間:2023年09月28日 08:28:43 作者:@年年
ZXing是一個開源的,支持多種格式的條形碼圖像處理庫,本文主要介紹了C#使用Zxing.dll組件解析二維碼的實現(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 = "識別結(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();//實例化對象
textBox1.Text = openfile.OpenFile();//調(diào)用方法,顯示圖片路徑
pathname = textBox1.Text;//獲取文件路徑
if (pathname != string.Empty)//這個判斷用處不大
{
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 = "識別結(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));//開始解析
}
}
}4.效果圖

到此這篇關(guān)于C#使用Zxing.dll組件解析二維碼的實現(xiàn)的文章就介紹到這了,更多相關(guān)C# Zxing.dll解析二維碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
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的實現(xiàn)詳解
如果你想玩轉(zhuǎn)C#?里面多線程,工廠模式,生產(chǎn)者/消費者,隊列等高級操作,就可以和我一起探索這個強大的線程安全提供阻塞和限制功能的C#神器類BlockingCollection吧2023-02-02

