Exemple #1
0
        public ActionResult MakeQRCodeImage(string url)
        {
            string str = StringService.FromHexString(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(str, Encoding.Default);

            //保存为PNG到内存流
            MemoryStream ms = new MemoryStream();

            image.Save(ms, ImageFormat.Png);

            //输出二维码图片
            byte[] bytes = ms.GetBuffer();

            return(File(bytes, @"image/jpeg"));
        }