资源简介

使用ZXing.dll实现条形码和二维码的生成与读取

资源截图

代码片段和文件信息

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;
using ZXing.Common;

namespace ZXingCode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //生成条形码-生成
        private void button1_Click(object sender EventArgs e)
        {
            //设置条形码规格
            EncodingOptions encodeOption = new EncodingOptions();
            //设置宽和高
            encodeOption.Height = 130;
            encodeOption.Width = 240;
            BarcodeWriter wr = new BarcodeWriter();
            wr.Options = encodeOption;
            //条形码:根据自己的需要选择条形码格式
            wr.Format = BarcodeFormat.EAN_13;
            //生成条形码
            Bitmap image = wr.Write(textBox1.Text);
            //显示
            pictureBox1.Image = image;
        }

        //生成条形码-保存
        private void button6_Click(object sender EventArgs e)
        {
            //保存图片
            saveImage(pictureBox1 textBox1.Text);
        }

        //读取条形码-选择图片
        private void button2_Click(object sender EventArgs e)
        {
            //打开图片
            openImage(textBox2 pictureBox2);
        }

        //读取条形码-读取
        private void button8_Click(object sender EventArgs e)
        {
            DecodingOptions decodeOption = new DecodingOptions();
            decodeOption.PossibleFormats = new List() { BarcodeFormat.EAN_13 };
            //读取条形码
            BarcodeReader br = new BarcodeReader();
            br.Options = decodeOption;
            Result result = br.Decode(pictureBox2.Image as Bitmap);
            if (result == null)
            {
                MessageBox.Show(“读取失败“);
            }
            else
            {
                //读取成功
                textBox3.Text = result.Text;
            }
        }

        //生成二维码-生成
        private void button3_Click(object sender EventArgs e)
        {
            //设置QR二维码的规格
            ZXing.QrCode.QrCodeEncodingOptions qrEncodeOption = new ZXing.QrCode.QrCodeEncodingOptions();
            //设置编码格式,否则中文乱码
            qrEncodeOption.CharacterSet = “UTF-8“;
            //设置宽和高
            qrEncodeOption.Height = 200;
            qrEncodeOption.Width = 200;
            //设置周围空白边距
            qrEncodeOption.Margin = 1;
            ZXing.BarcodeWriter wr = new BarcodeWriter();
            //二维码
            wr.Format = BarcodeFormat.QR_CODE;
            wr.Options = qrEncodeOption;
            //生成二维码
            Bitmap image = wr.Write(textBox4.Text);
            //显示
            pictureBox3.Image = image;
        }

        //生成二维码-保存
        private void button7_Click(object sender EventArgs e)
        {
            //保存图片
            saveImage(pictureBox3 textBox4

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-09 17:10  ZXingCode\
     目录           0  2017-01-09 17:10  ZXingCode\ZXing\
     目录           0  2017-01-09 17:10  ZXingCode\ZXing\net2.0\
     文件      540492  2014-04-02 03:44  ZXingCode\ZXing\net2.0\zxing.xml
     文件      435712  2014-04-02 03:44  ZXingCode\ZXing\net2.0\zxing.dll
     文件     1351168  2014-04-08 03:55  ZXingCode\ZXing\net2.0\zxing.pdb
     目录           0  2017-01-09 17:10  ZXingCode\ZXing\net3.5\
     文件      434176  2014-04-02 04:21  ZXingCode\ZXing\net3.5\zxing.dll
     文件     1351168  2014-04-08 03:55  ZXingCode\ZXing\net3.5\zxing.pdb
     文件      536064  2014-04-02 04:21  ZXingCode\ZXing\net3.5\zxing.xml
     目录           0  2017-01-09 17:10  ZXingCode\ZXing\net4.0\
     文件      494760  2014-04-02 03:44  ZXingCode\ZXing\net4.0\zxing.xml
     文件      430080  2014-04-02 03:44  ZXingCode\ZXing\net4.0\zxing.dll
     文件     1216000  2014-04-08 03:55  ZXingCode\ZXing\net4.0\zxing.pdb
     文件        9221  2014-04-02 03:44  ZXingCode\ZXing\net4.0\zxing.presentation.xml
     文件       20992  2014-04-02 03:44  ZXingCode\ZXing\net4.0\zxing.presentation.dll
     文件       42496  2014-04-08 03:55  ZXingCode\ZXing\net4.0\zxing.presentation.pdb
     目录           0  2017-01-09 17:10  ZXingCode\ZXing\net4.5\
     文件      494333  2014-04-02 05:01  ZXingCode\ZXing\net4.5\zxing.xml
     文件      420864  2014-04-02 05:01  ZXingCode\ZXing\net4.5\zxing.dll
     文件     1216000  2014-04-08 03:55  ZXingCode\ZXing\net4.5\zxing.pdb
     目录           0  2017-01-09 17:09  ZXingCode\ZXingCode\
     文件         187  2017-01-09 16:27  ZXingCode\ZXingCode\App.config
     文件       20431  2017-01-09 16:59  ZXingCode\ZXingCode\Form1.Designer.cs
     文件        6056  2017-01-09 17:09  ZXingCode\ZXingCode\Form1.cs
     文件        5817  2017-01-09 16:59  ZXingCode\ZXingCode\Form1.resx
     文件         521  2017-01-09 16:27  ZXingCode\ZXingCode\Program.cs
     目录           0  2017-01-09 16:27  ZXingCode\ZXingCode\Properties\
     文件        1342  2017-01-09 16:27  ZXingCode\ZXingCode\Properties\AssemblyInfo.cs
     文件        2870  2017-01-09 16:27  ZXingCode\ZXingCode\Properties\Resources.Designer.cs
     文件        5612  2017-01-09 16:27  ZXingCode\ZXingCode\Properties\Resources.resx
............此处省略31个文件信息

评论

共有 条评论