C#利用QRCoder生产二维码

系统使用.NET4.5.1

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QRCoder;
using System.Drawing;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strCode = "http://www.dotnetcms.org";
        QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
        QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q);
        QRCode qrcode = new QRCode(qrCodeData);

        // qrcode.GetGraphic 方法可参考最下发“补充说明”
        Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false);
        MemoryStream ms = new MemoryStream();
        qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

        // 如果想保存图片 可使用  qrCodeImage.Save(filePath);

        // 响应类型
        Response.ContentType = "image/Jpeg";
        //输出字符流
        Response.BinaryWrite(ms.ToArray());
    }
}

 

 

 

https://files.cnblogs.com/files/mqingqing123/QR.rar

posted @ 2018-08-21 21:40  启明星工作室  阅读(266)  评论(0编辑  收藏  举报