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));//開始解析
}
}
}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)文章
C#數(shù)據(jù)結(jié)構(gòu)與算法揭秘四 雙向鏈表
上節(jié)說過這節(jié)會(huì)講雙向鏈表,環(huán)形鏈表和應(yīng)用舉例,我們開始吧!?。?!2012-11-11
c#編寫的高并發(fā)數(shù)據(jù)庫控制訪問代碼
往往大數(shù)據(jù)量,高并發(fā)時(shí), 瓶頸都在數(shù)據(jù)庫上, 好多人都說用數(shù)據(jù)庫的復(fù)制,發(fā)布, 讀寫分離等技術(shù), 但主從數(shù)據(jù)庫之間同步時(shí)間有延遲.2015-03-03
C#如何通過匿名類直接使用訪問JSON數(shù)據(jù)詳解
這篇文章主要給大家介紹了關(guān)于C#如何通過匿名類直接使用訪問JSON數(shù)據(jù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起看看吧。2018-02-02
C#實(shí)現(xiàn)Quartz任務(wù)調(diào)度的示例代碼
使用 Quartz.NET,你可以很容易地安排任務(wù)在應(yīng)用程序啟動(dòng)時(shí)運(yùn)行,或者每天、每周、每月的特定時(shí)間運(yùn)行,甚至可以基于更復(fù)雜的調(diào)度規(guī)則,本文給大家介紹了C#實(shí)現(xiàn)Quartz任務(wù)調(diào)度,需要的朋友可以參考下2024-04-04
unity中實(shí)現(xiàn)Edge瀏覽器鼠標(biāo)手勢(shì)的功能思路詳解
這篇文章主要介紹了unity中實(shí)現(xiàn)Edge瀏覽器鼠標(biāo)手勢(shì)的功能思路詳解,實(shí)現(xiàn)起來其實(shí)并不復(fù)雜,涉及的技術(shù)點(diǎn)有pc端和移動(dòng)端屏幕拖動(dòng)事件,二維向量的相關(guān)運(yùn)算,手勢(shì)匹配算法,事件系統(tǒng)設(shè)計(jì)模式,需要的朋友可以參考下2023-12-12
SQL+C#實(shí)現(xiàn)獲得當(dāng)前月的第一天與最后一天
本文分享了SQL+C#獲得當(dāng)前月的第一天與最后一天的代碼實(shí)例,代碼簡潔,適合初學(xué)者參考。需要的朋友可以看下2016-12-12
C# 使用動(dòng)態(tài)庫DllImport("kernel32")讀寫ini文件的步驟
kernel32.dll是Windows中非常重要的32位動(dòng)態(tài)鏈接庫文件,屬于內(nèi)核級(jí)文件,這篇文章主要介紹了C# 利用動(dòng)態(tài)庫DllImport("kernel32")讀寫ini文件,需要的朋友可以參考下2023-05-05

