C#使用ZXing.dll產生二維碼圖片

/// <summary>
    /// 產生二維碼圖片
    /// </summary>
    /// <param name="formId">申請單號,作爲圖片名稱</param>
    /// <param name="text">文本</param>
    /// <param name="filePath">保存路徑</param>
    public static void createQRCode(string formId,string text,string filePath)
    {
        try
        {
            EncodingOptions options = null;
            BarcodeWriter writer = null;
            //width、height为二维码图片的宽度和高度
            int width = 120;
            int height = 120;
            var size = GetMinSize(text + formId); //获取内容尺寸,未经放大的最小尺寸
            width = size[2] * (width / size[2]); //最大限度的宽;
            height = size[3] * (height / size[3]);//最大限度的高
            options = new QrCodeEncodingOptions
            {
                DisableECI = true,
                CharacterSet = "UTF-8",
                Width = width,
                Height = height,
                Margin = 0
            };
            writer = new BarcodeWriter();
            //BarcodeFormat可以设置条码编码类型:條形碼CODE_128、二維碼QR_CODE
            writer.Format = BarcodeFormat.QR_CODE;
            writer.Options = options;
            //options.PureBarcode = true;// 是否是纯码,如果为 false,则会在條碼下方显示数字

            //生成二维码信息的内容
            Bitmap bitmap = writer.Write(text + formId);
            //二維碼保存文件
            bitmap.Save(filePath + formId + ".png");
        }
        catch (Exception e)
        {
            throw e;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值