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