在.net core web项目中生成二维码
2018-12-19 15:13 tshaoguo 阅读(1277) 评论(2) 编辑 收藏 举报第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步:运行测试