1.添加QRCoder包引用
2. public IActionResult MakeQrCode()
{
string url="https://www.baidu.com";
var generator = new QRCodeGenerator();
var codeData = generator.CreateQrCode(str,QRCodeGenerator.ECCLevel.M,true);
var qrcode = new QRCode(codeData);
var qrImage = qrcode.GetGraphic(100,Color.Black,Color.White,true);
var ms = new MemoryStream();
//图片格式指定为png
qrImage.Save(ms,ImageFormat.Jpeg);
byte[] bytes = ms.GetBuffer();
ms.Close();
return File(bytes, "image/Png");
}
原文地址:https://www.cnblogs.com/lonelyxmas/p/12028874.html
时间: 2024-10-06 05:53:37