需要引用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; }