v2rayN/v2rayN/v2rayN.Desktop/Views/QrcodeView.axaml.cs

41 lines
843 B
C#
Raw Normal View History

2025-01-30 09:10:05 +00:00
using Avalonia.Controls;
using Avalonia.Media.Imaging;
2025-03-01 11:56:52 +00:00
using Avalonia.Threading;
namespace v2rayN.Desktop.Views;
public partial class QrcodeView : UserControl
{
public QrcodeView()
{
InitializeComponent();
}
2025-01-10 06:23:03 +00:00
public QrcodeView(string? url)
{
InitializeComponent();
txtContent.Text = url;
imgQrcode.Source = GetQRCode(url);
txtContent.GotFocus += (_, _) => Dispatcher.UIThread.Post(() => { txtContent.SelectAll(); });
}
private Bitmap? GetQRCode(string? url)
{
var bytes = QRCodeHelper.GenQRCode(url);
return ByteToBitmap(bytes);
}
2024-10-19 06:30:14 +00:00
private Bitmap? ByteToBitmap(byte[]? bytes)
{
if (bytes is null)
2024-10-19 06:30:14 +00:00
{
return null;
}
using var ms = new MemoryStream(bytes);
return new Bitmap(ms);
}
2025-01-30 09:10:05 +00:00
}