C#生成长字串的二维码 办法


       string url="weixin://wxpay/bizpayurl?sign=C380BEC2BFD727A4B6845133519F3AD6appid=************&mch_id=******&product_id=****&time_stamp=20210124&nonce_str=5K8264ILTKCH16CQ2502SI8ZNMTM67VS";



        TextBox1.Text = url;

        //初始化二维码生成工具
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
        qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
        qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
        qrCodeEncoder.QRCodeVersion = 0;
        qrCodeEncoder.QRCodeScale = 4;

        //将字符串生成二维码图片
        Bitmap image = qrCodeEncoder.Encode(url, Encoding.Default);

        Bitmap bt;
        bt = qrCodeEncoder.Encode(url, Encoding.Default);

        //保存为PNG到内存流  
        MemoryStream ms = new MemoryStream();
        image.Save(ms, ImageFormat.Png);

        //输出二维码图片
       // Response.BinaryWrite(ms.GetBuffer());
       // Response.End();




        string filename = string.Format(DateTime.Now.ToString(), "yyyymmddhhmmss")
         + ".jpg";
        filename = filename.Replace(" ", "");
        filename = filename.Replace(":", "");
        filename = filename.Replace("-", "");
        filename = filename.Replace("/", "");
        bt.Save(Server.MapPath("~/tutu/") + filename + ".jpg");
        this.Image1.ImageUrl = "~/tutu/" + filename + ".jpg";

webform
桂ICP备16004754号