c#生成二维码

时间:2022-11-24 10:38:06
        String link ="www.baidu.com";//这里一般是一个链接

封装后的方法,直接调用就可以了

 public void CreateQRCode(string content)
    {
        
        var qrCodeEncoder = new QRCodeEncoder
        {
            QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE,
            QRCodeScale = 6,
            QRCodeVersion = 4,
            QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M
        };
        System.Drawing.Image QRCodeImg = qrCodeEncoder.Encode(content);
        MemoryStream stream = new MemoryStream();
        QRCodeImg.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        Response.ClearContent();
        Response.ContentType = "image/Png";
        Response.BinaryWrite(stream.ToArray());
    }