• C#zxing生成二维码


    本示例是zxing生成二维码信息,需要应用zxing。

        public static class QRCode
        {
            public static Bitmap GetBitmap(string sContent, int iWidth, int iHeight)
            {
                BarcodeWriter writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE;
                QrCodeEncodingOptions options = new QrCodeEncodingOptions();
                options.DisableECI = true;
                //设置内容编码
                options.CharacterSet = "UTF-8";
                //设置二维码的宽度和高度
                options.Width = iWidth;
                options.Height = iHeight;
                //设置二维码的边距,单位不是固定像素
                options.Margin = 0; // 设置周围空白边距
                writer.Options = options;
    
                return writer.Write(sContent);
            }
    
            public static string GetBitmapBase64String(string sContent, int iWidth, int iHeight)
            {
                Bitmap imgBitmap = GetBitmap(sContent, iWidth, iHeight);
    
                string filename = System.Windows.Forms.Application.StartupPath + "\\QrCodeTemp.jpg";
                imgBitmap.Save(filename, ImageFormat.Jpeg);
    
                MemoryStream ms = new MemoryStream();
                imgBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] arr = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(arr, 0, (int)ms.Length);
                ms.Close();
                imgBitmap.Dispose();
                string strBaser64 = Convert.ToBase64String(arr);
                return strBaser64;
            }
        }
    }

    下载地址:

    「zxing.dll」https://www.aliyundrive.com/s/CtoCqKCwkcy

  • 相关阅读:
    数论2&莫&杜
    虚树学习笔记
    LinkCutTree学习笔记
    FWT学习笔记
    容斥
    线段树合并
    线性基
    FFT_应用和例题
    斜率优化
    Redis中String的底层实现
  • 原文地址:https://www.cnblogs.com/leebokeyuan/p/16306022.html
Copyright © 2020-2023  润新知