• 生成二维码


    /// <summary>
    /// 
    /// </summary>
    /// <param name="userCode"></param>
    /// <returns></returns>
    public string generateQRCode(string visitUrl)
            {
               
                string filename = string.Empty;
                string filepath = string.Empty;
    
                string txt_qr = userCode;
                string qrEncoding = "Byte";
                string Level = "M";
                string txt_ver = "7";
                string txt_size = "4";
    
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                String encoding = qrEncoding;
                if (encoding == "Byte")
                {
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                }
                else if (encoding == "AlphaNumeric")
                {
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
                }
                else if (encoding == "Numeric")
                {
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
                }
                try
                {
                    int scale = Convert.ToInt16(txt_size);
                    qrCodeEncoder.QRCodeScale = scale;
                }
                catch (Exception ex)
                {
                    return "";
                }
                try
                {
                    int version = Convert.ToInt16(txt_ver);
                    qrCodeEncoder.QRCodeVersion = version;
                }
                catch (Exception ex)
                {
                    return "";
                }
                string errorCorrect = Level;
                if (errorCorrect == "L")
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
                else if (errorCorrect == "M")
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                else if (errorCorrect == "Q")
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
                else if (errorCorrect == "H")
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
    
                Image image;
                String data = txt_qr;
                image = qrCodeEncoder.Encode(data);
                filename = Guid.NewGuid().ToString() + ".jpg";
                filepath = ConfigurationManager.AppSettings["userCode"] + filename;
                System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.OpenOrCreate, 
    
    System.IO.FileAccess.Write);
                image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                fs.Close();
                image.Dispose();
                return filepath;
            }

     注:在使用之前需要引用  “ThoughtWorks.QRCode.dll”  

     下载地址:ThoughtWorks.QRCode.zip

  • 相关阅读:
    导数的定义(一些常用函数的求导公式)
    ubuntu后台运行命令行
    数学公式做图网站
    导数可导性与连续性关系
    nutch 二次开发
    matplotlib绘制精美的图表(这是教程哦)
    JS获取今天和上个月的今天
    js修改url参数,无刷新更换页面url
    给网页复制的内容添加东西
    MySQL下载安装详情教程
  • 原文地址:https://www.cnblogs.com/Darker-Samuel/p/4560976.html
Copyright © 2020-2023  润新知