欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#使用Zxing.dll組件解析二維碼的實(shí)現(xiàn)

 更新時(shí)間:2023年09月28日 08:28:43   作者:@年年  
ZXing是一個(gè)開(kāi)源的,支持多種格式的條形碼圖像處理庫(kù),本文主要介紹了C#使用Zxing.dll組件解析二維碼的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下

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)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

最新評(píng)論