(71)C# zxing.net 二维码 条形码

     https://archive.codeplex.com/?p=zxingnet

 https://github.com/wangmeijian/blog/blob/master/docs/%E4%BA%8C%E7%BB%B4%E7%A0%81%E7%9A%84%E7%A7%98%E5%AF%86.MD 揭秘二维码

 

using System;
using System.Drawing;
using System.Windows.Forms;
using ZXing;
using ZXing.QrCode;

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

        private void button1_Click(object sender, EventArgs e)
        {
            BarcodeWriter barcodeWriter = new BarcodeWriter();
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();
            //options.Width = 10;
            //options.Height = 10;
            options.Width = pictureBox1.Width;
            options.Height = pictureBox1.Height;
            options.DisableECI = true;
            options.CharacterSet = "UTF-8";
            options.Margin = 1;
            //二维码格式
            barcodeWriter.Format= BarcodeFormat.QR_CODE; 
            barcodeWriter.Options = options;
            //内容
            Bitmap map = barcodeWriter.Write("hello world");
            //将Bitmap转换成Image对象
            Image img = Image.FromHbitmap(map.GetHbitmap());
            pictureBox1.Image = map;
        }
    }
}

运行

BarcodeFormat.CODE_128 ;//一维码

 

posted @ 2020-01-01 11:09  富坚老贼  阅读(295)  评论(0编辑  收藏  举报