C# 二维码帮助类 QRCoder

    /// 
    /// 二维码帮助类
    /// 
    public class QrCodeHelper
    {


        /// 
        /// 获取二维码
        /// 
        /// 
        /// 
        /// 
        public static Bitmap GetQRcode(string url,int  pixel) {


            QRCodeGenerator generator = new QRCodeGenerator();

            QRCodeData codeData = generator.CreateQrCode(url, QRCodeGenerator.ECCLevel.M, true);

            QRCode qrcode = new QRCode(codeData);

            Bitmap bitmap = qrcode.GetGraphic(pixel, Color.Black, Color.White, true);
     
            return bitmap;

        }


    }
        /// 
        /// 获取下载链接二维码
        /// 
        [HttpGet("GetUrl")]
        [IgnoreFilter]
        public void GetQCode() {

            Response.ContentType = "image/jpeg";

            var bitmap = QrCodeHelper.GetQRcode("http://www.baidu.com",8);
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, ImageFormat.Jpeg);
            Response.Body.WriteAsync(ms.GetBuffer(), 0, Convert.ToInt32(ms.Length));

            Response.Body.Close();

        }

 

你可能感兴趣的:(C#,.net)