zoukankan      html  css  js  c++  java
  • 利用ZXing生成条码二维码例子

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using ZXing.Common;
    using ZXing;
    using ZXing.QrCode;
    using System.Windows.Forms;
    using System.Text.RegularExpressions;
    
    namespace BarCodePrint
    {
        class BarCodeGenerate
        {
            ///<summary>
            ///生成条形码
            ///</summary>
            ///<paramname="pictureBox1"></param>
            ///<paramname="Contents"></param>
            public Bitmap CreateBarCodeBitMap(string Contents, int Width, int Height)
            {
                //Regex rg = new Regex("^[0-9]{12}$");
                //if (!rg.IsMatch(Contents))
                //{
                //    MessageBox.Show("本例子采用EAN_13编码,需要输入12位数字");
                //    return;
                //}
    
                EncodingOptions options = null;
                BarcodeWriter writer = null;
                options = new EncodingOptions
                {
                    Width = Width,
                    Height = Height
                };
                writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.CODE_128;
                writer.Options = options;
    
    
                Bitmap bitmap = writer.Write(Contents);
    
                return bitmap;
            }
    
    
    
            ///<summary>
            ///生成条形码
            ///</summary>
            ///<paramname="pictureBox1"></param>
            ///<paramname="Contents"></param>
            public void CreateBarCode(PictureBox pictureBox1, string Contents)
            {
                //Regex rg = new Regex("^[0-9]{12}$");
                //if (!rg.IsMatch(Contents))
                //{
                //    MessageBox.Show("本例子采用EAN_13编码,需要输入12位数字");
                //    return;
                //}
    
                EncodingOptions options = null;
                BarcodeWriter writer = null;
                options = new EncodingOptions
                {
                    Width = pictureBox1.Width,
                    Height = pictureBox1.Height
                };
                writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.CODE_128;
                writer.Options = options;
    
                Bitmap bitmap = writer.Write(Contents);
                pictureBox1.Image = bitmap;
            }
    
    
    
    
            ///<summary>
            ///生成二维码
            ///</summary>
            ///<paramname="pictureBox1"></param>
            ///<paramname="Contents"></param>
            public Bitmap CreateQRCode(string Contents, int Width, int Height)
            {
                if (Contents == string.Empty)
                {
                    MessageBox.Show("输入内容不能为空!");
    
                }
    
                EncodingOptions options = null;
                BarcodeWriter writer = null;
    
                options = new QrCodeEncodingOptions
                {
                    DisableECI = true,
                    CharacterSet = "UTF-8",
                    Width = Width,
                    Height = Height
                };
                writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE;
                writer.Options = options;
    
    
                Bitmap bitmap = writer.Write(Contents);
                return bitmap;
            }
    
    
            ///<summary>
            ///生成二维码
            ///</summary>
            ///<paramname="pictureBox1"></param>
            ///<paramname="Contents"></param>
            public void CreateQuickMark(PictureBox pictureBox1, string Contents)
            {
                if (Contents == string.Empty)
                {
                    MessageBox.Show("输入内容不能为空!");
                    return;
                }
    
                EncodingOptions options = null;
                BarcodeWriter writer = null;
    
                options = new QrCodeEncodingOptions
                {
                    DisableECI = true,
                    CharacterSet = "UTF-8",
                    Width = pictureBox1.Width,
                    Height = pictureBox1.Height
                };
                writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE;
                writer.Options = options;
    
    
                Bitmap bitmap = writer.Write(Contents);
                pictureBox1.Image = bitmap;
            }
    
            ///<summary>
            ///解码
            ///</summary>
            ///<paramname="pictureBox1"></param>
            public void Decode(PictureBox pictureBox1)
            {
                BarcodeReader reader = new BarcodeReader();
                Result result = reader.Decode((Bitmap)pictureBox1.Image);
            }
        }
    }
  • 相关阅读:
    递归函数及Java范例
    笔记本的硬盘坏了
    “References to generic type List should be parameterized”
    配置管理软件(configuration management software)介绍
    WinCE文件目录定制及内存调整
    使用Silverlight for Embedded开发绚丽的界面(3)
    wince国际化语言支持
    Eclipse IDE for Java EE Developers 与Eclipse Classic 区别
    WinCE Heartbeat Message的实现
    使用Silverlight for Embedded开发绚丽的界面(2)
  • 原文地址:https://www.cnblogs.com/CelonY/p/14721351.html
Copyright © 2011-2022 走看看