显示二维码
发布于 3/10/2020 9:45:10 PM   133次围观  0条评论
发表于 3/10/2020 9:45:10 PM   133人围观  0条评论
安装扩展 ``` dotnet add package QRCoder ``` 添加代码 ``` [Route("api/[controller]")] [ApiController] public class ValuesController : ControllerBase { [HttpGet] public FileResult Get() { QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.L; using (QRCodeGenerator qrGenerator = new QRCodeGenerator()) { using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("Hello .NET Core", eccLevel)) { using (QRCode qrCode = new QRCode(qrCodeData)) { Bitmap bp = qrCode.GetGraphic(20, Color.Black, Color.White,true); return File(Bitmap2Byte(bp), "image/png", "hello-dotnetcore.png"); } } } } public static byte[] Bitmap2Byte(Bitmap bitmap) { using (MemoryStream stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Jpeg); byte[] data = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(data, 0, Convert.ToInt32(stream.Length)); return data; } } ```
立即登录,发表评论
没有帐号?立即注册
{{$.post.CommentNum}} 条评论