mirror of
https://github.com/2dust/v2rayN.git
synced 2026-09-29 02:07:58 +03:00
* Interaction * Remove view action * ViewModel-first * MainGirdOrientation Hot Reload * Fix avalonia preview * Remove CloseWindowInteraction * Fix * Avoid threading issues * Fix * ProfilesSelect * Try fix previewer * Remove AppEvents.ProfilesRefreshRequested * Remove AppEvents.SubscriptionsRefreshRequested * Remove AppEvents.ProxiesReloadRequested * Remove AppEvents.AdjustMainLvColWidthRequested * Remove AppEvents.SetDefaultServerRequested * Remove AppEvents.RoutingsMenuRefreshRequested * Remove AppEvents.TestServerRequested * Remove AppEvents.InboundDisplayRequested * Remove AppEvents.SubscriptionsUpdateRequested * Remove AppEvents.ShowHideWindowRequested * Remove AppEvents.ReloadRequested * Remove AppEvents.AddServerRequested * Fix
52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
namespace v2rayN.Desktop.Views;
|
|
|
|
public partial class QrcodeView : UserControl
|
|
{
|
|
public QrcodeView()
|
|
{
|
|
InitializeComponent();
|
|
if (Design.IsDesignMode)
|
|
{
|
|
//const string url = Global.AppName;
|
|
const string url = Global.SystemProxyExceptionsWindows;
|
|
txtContent.Text = url;
|
|
imgQrcode.Source = GetQRCode(url);
|
|
}
|
|
}
|
|
|
|
public QrcodeView(string? url)
|
|
{
|
|
InitializeComponent();
|
|
|
|
txtContent.Text = url;
|
|
imgQrcode.Source = GetQRCode(url);
|
|
|
|
txtContent.GotFocus += (_, _) => Dispatcher.UIThread.Post(() => { txtContent.SelectAll(); });
|
|
}
|
|
|
|
private Bitmap? GetQRCode(string? url)
|
|
{
|
|
try
|
|
{
|
|
var bytes = QRCodeUtils.GenQRCode(url);
|
|
return ByteToBitmap(bytes);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logging.SaveLog("GetQRCode", ex);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private Bitmap? ByteToBitmap(byte[]? bytes)
|
|
{
|
|
if (bytes is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
using var ms = new MemoryStream(bytes);
|
|
return new Bitmap(ms);
|
|
}
|
|
}
|