“C#生成二维码“
作者:互联网
需要引用QRCoder
[AcceptVerbs("get")]
[Route("api/UserChannel/GetQR")]
public HttpResponseMessage QR(string code)
{
code = HttpUtility.UrlDecode(code);
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(10, Color.Black, Color.White, null, 15, 6, false);
MemoryStream ms = new MemoryStream();
qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
qrCodeImage.Dispose();
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(ms.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
return result;
}
标签:code,C#,HttpResponseMessage,QRCodeGenerator,生成,二维码,result,new,qrCodeImage 来源: https://blog.csdn.net/weixin_40068689/article/details/122061956