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 = "識別結果是:" + 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();//調用方法,顯示圖片路徑 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 = "識別結果是:" + 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.效果圖
到此這篇關于C#使用Zxing.dll組件解析二維碼的實現(xiàn)的文章就介紹到這了,更多相關C# Zxing.dll解析二維碼內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
unity中實現(xiàn)Edge瀏覽器鼠標手勢的功能思路詳解
這篇文章主要介紹了unity中實現(xiàn)Edge瀏覽器鼠標手勢的功能思路詳解,實現(xiàn)起來其實并不復雜,涉及的技術點有pc端和移動端屏幕拖動事件,二維向量的相關運算,手勢匹配算法,事件系統(tǒng)設計模式,需要的朋友可以參考下2023-12-12C# 使用動態(tài)庫DllImport("kernel32")讀寫ini文件的步驟
kernel32.dll是Windows中非常重要的32位動態(tài)鏈接庫文件,屬于內核級文件,這篇文章主要介紹了C# 利用動態(tài)庫DllImport("kernel32")讀寫ini文件,需要的朋友可以參考下2023-05-05