系统使用.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()); } }