改文章引用至:https://www.cnblogs.com/wlays/p/7994393.html
1.使用VS打开项目,项目->右键->管理Nuget程序包,然后选择联机,在输入框中输入QRCoder,如下图所示:
安装此项目
2. 创建一个WebForm项目
protected void Page_Load(object sender, EventArgs e) { string strCode = "https://www.baidu.com/"; var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); var qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); Response.ContentType = "image/Jpeg"; Response.BinaryWrite(ms.ToArray()); }
3. 运行此项目, 结果如下