先添加QRCoder NuGet程序包(生成二维码要用到)
// 生成二维码的内容
string strCode = “123456”; 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, ImageFormat.Jpeg); //如果想保存图片 可使用qrCodeImage.Save("E:/7.jpg"); //Convert.ToBase64String(ms.ToArray()); context.Response.Write(Convert.ToBase64String(ms.ToArray()));