btcpayserver/BTCPayServer/Blazor/QrCode.razor
d11n 272cc3d3c9
POS: Option for user sign in via the QR code (#6231)
* Login Code: Turn into Blazor component and extend with data for the app

* POS: Add login code for POS frontend

* Improve components, fix test
2024-09-26 19:10:14 +09:00

30 lines
1015 B
Plaintext

@using QRCoder
@if (!string.IsNullOrEmpty(Data))
{
<img @attributes="Attrs" style="image-rendering:pixelated;image-rendering:-moz-crisp-edges;min-width:@(Size)px;min-height:@(Size)px" src="data:image/png;base64,@(GetBase64(Data))" class="@CssClass" alt="@Data" />
}
@code {
[Parameter, EditorRequired]
public string Data { get; set; }
[Parameter]
public int Size { get; set; } = 256;
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> Attrs { get; set; }
private static readonly QRCodeGenerator QrGenerator = new();
private string GetBase64(string data)
{
var qrCodeData = QrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q);
var qrCode = new PngByteQRCode(qrCodeData);
var bytes = qrCode.GetGraphic(5, [0, 0, 0, 255], [0xf5, 0xf5, 0xf7, 255]);
return Convert.ToBase64String(bytes);
}
private string CssClass => $"qr-code {(Attrs?.ContainsKey("class") is true ? Attrs["class"] : "")}".Trim();
}