diff --git a/v2rayN/ServiceLib/Common/QRCodeUtils.cs b/v2rayN/ServiceLib/Common/QRCodeUtils.cs
index 3d3dc90b..d9015367 100644
--- a/v2rayN/ServiceLib/Common/QRCodeUtils.cs
+++ b/v2rayN/ServiceLib/Common/QRCodeUtils.cs
@@ -1,4 +1,5 @@
using QRCoder;
+using QRCoder.Exceptions;
using SkiaSharp;
using ZXing.SkiaSharp;
@@ -8,10 +9,45 @@ public class QRCodeUtils
{
public static byte[]? GenQRCode(string? url)
{
+ if (url.IsNullOrEmpty())
+ {
+ return null;
+ }
using QRCodeGenerator qrGenerator = new();
- using var qrCodeData = qrGenerator.CreateQrCode(url ?? string.Empty, QRCodeGenerator.ECCLevel.Q);
- using PngByteQRCode qrCode = new(qrCodeData);
- return qrCode.GetGraphic(20);
+ DataTooLongException? lastDtle = null;
+
+ var levels = new[]
+ {
+ QRCodeGenerator.ECCLevel.H,
+ QRCodeGenerator.ECCLevel.Q,
+ QRCodeGenerator.ECCLevel.M,
+ QRCodeGenerator.ECCLevel.L
+ };
+ foreach (var level in levels)
+ {
+ try
+ {
+ using var qrCodeData = qrGenerator.CreateQrCode(url, level);
+ using PngByteQRCode qrCode = new(qrCodeData);
+ return qrCode.GetGraphic(20);
+ }
+ catch (DataTooLongException ex)
+ {
+ lastDtle = ex;
+ continue;
+ }
+ catch
+ {
+ throw;
+ }
+ }
+
+ if (lastDtle != null)
+ {
+ throw lastDtle;
+ }
+
+ return null;
}
public static string? ParseBarcode(string? fileName)
diff --git a/v2rayN/v2rayN.Desktop/Views/QrcodeView.axaml b/v2rayN/v2rayN.Desktop/Views/QrcodeView.axaml
index 90d94685..b67a7a1f 100644
--- a/v2rayN/v2rayN.Desktop/Views/QrcodeView.axaml
+++ b/v2rayN/v2rayN.Desktop/Views/QrcodeView.axaml
@@ -4,19 +4,25 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- d:DesignHeight="480"
- d:DesignWidth="400"
+ xmlns:sys="clr-namespace:System;assembly=netstandard"
+ d:DesignHeight="600"
+ d:DesignWidth="600"
mc:Ignorable="d">
+
+
+ 500
+
+
+ Width="{StaticResource QrcodeWidth}"
+ Height="{StaticResource QrcodeWidth}" />
+
+ 500
+
+
-
+
-
\ No newline at end of file
+