2021-12-27 13:15:43 +09:00
|
|
|
using System;
|
2020-12-22 03:18:51 +01:00
|
|
|
using System.Drawing;
|
|
|
|
using Microsoft.AspNetCore.Html;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
|
|
|
using QRCoder;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Components.QRCode
|
|
|
|
{
|
|
|
|
public class QRCode : ViewComponent
|
|
|
|
{
|
2023-04-10 11:07:03 +09:00
|
|
|
private static QRCodeGenerator _qrGenerator = new();
|
|
|
|
|
2020-12-22 03:18:51 +01:00
|
|
|
public IViewComponentResult Invoke(string data)
|
|
|
|
{
|
2023-02-22 03:47:02 +01:00
|
|
|
var qrCodeData = _qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q);
|
|
|
|
var qrCode = new PngByteQRCode(qrCodeData);
|
|
|
|
var bytes = qrCode.GetGraphic(5, new byte[] { 0, 0, 0, 255 }, new byte[] { 0xf5, 0xf5, 0xf7, 255 });
|
2021-12-27 13:15:43 +09:00
|
|
|
var b64 = Convert.ToBase64String(bytes);
|
2023-02-22 03:47:02 +01:00
|
|
|
return new HtmlContentViewComponentResult(new HtmlString($"<img style=\"image-rendering:pixelated;image-rendering:-moz-crisp-edges;min-width:256px;min-height:256px\" src=\"data:image/png;base64,{b64}\" class=\"qr-code\" />"));
|
2020-12-22 03:18:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|