第1步:添加QRCoder包引用
Install-Package QRCoder
第2步:编写生成二维码的代码
public IActionResult QrCode()
{
QRCodeGenerator generator = new QRCodeGenerator();
string Url = "http://www.baidu.com";
QRCodeData codeData = generator.CreateQrCode(Url, QRCodeGenerator.ECCLevel.M, true);
QRCoder.QRCode qrcode = new QRCoder.QRCode(codeData);
Bitmap qrImage = qrcode.GetGraphic(100, Color.Black, Color.White, true);
MemoryStream ms = new MemoryStream();
qrImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] bytes = ms.GetBuffer();
ms.Close();
return File(bytes, "image/Png");
}
第3步:运行测试