mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-27 02:34:41 +00:00
Compare commits
4 commits
1d54f88e79
...
5c4f1ea38f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c4f1ea38f | ||
|
|
18ac76e683 | ||
|
|
3e1e23a524 | ||
|
|
534c7ab444 |
7 changed files with 78 additions and 22 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>7.14.11</Version>
|
||||
<Version>7.14.12</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
<PackageVersion Include="ReactiveUI" Version="20.4.1" />
|
||||
<PackageVersion Include="ReactiveUI.Fody" Version="19.5.41" />
|
||||
<PackageVersion Include="ReactiveUI.WPF" Version="20.4.1" />
|
||||
<PackageVersion Include="Semi.Avalonia" Version="11.2.1.9" />
|
||||
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.9" />
|
||||
<PackageVersion Include="Semi.Avalonia" Version="11.2.1.10" />
|
||||
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.10" />
|
||||
<PackageVersion Include="Splat.NLog" Version="16.2.1" />
|
||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
<PackageVersion Include="TaskScheduler" Version="2.12.2" />
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
||||
<UserControl.Resources>
|
||||
<sys:Double x:Key="QrcodeWidth">500</sys:Double>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Margin="32" RowDefinitions="Auto,Auto">
|
||||
<Image
|
||||
Name="imgQrcode"
|
||||
Width="300"
|
||||
Height="300" />
|
||||
Width="{StaticResource QrcodeWidth}"
|
||||
Height="{StaticResource QrcodeWidth}" />
|
||||
|
||||
<TextBox
|
||||
x:Name="txtContent"
|
||||
Grid.Row="1"
|
||||
Width="300"
|
||||
Width="{StaticResource QrcodeWidth}"
|
||||
MaxHeight="100"
|
||||
Margin="{StaticResource MarginTb8}"
|
||||
VerticalAlignment="Center"
|
||||
|
|
|
|||
|
|
@ -23,8 +23,16 @@ public partial class QrcodeView : UserControl
|
|||
|
||||
private Bitmap? GetQRCode(string? url)
|
||||
{
|
||||
var bytes = QRCodeUtils.GenQRCode(url);
|
||||
return ByteToBitmap(bytes);
|
||||
try
|
||||
{
|
||||
var bytes = QRCodeUtils.GenQRCode(url);
|
||||
return ByteToBitmap(bytes);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog("GetQRCode", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap? ByteToBitmap(byte[]? bytes)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ public class QRCodeUtils
|
|||
var qrCodeImage = ServiceLib.Common.QRCodeUtils.GenQRCode(strContent);
|
||||
return qrCodeImage is null ? null : ByteToImage(qrCodeImage);
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog("GetQRCode", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<UserControl
|
||||
<UserControl
|
||||
x:Class="v2rayN.Views.QrcodeView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
|
|
@ -6,28 +6,33 @@
|
|||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="300"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
d:DesignHeight="600"
|
||||
d:DesignWidth="600"
|
||||
Style="{StaticResource ViewGlobal}"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<sys:Double x:Key="QrcodeWidth">500</sys:Double>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Margin="32">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="60" />
|
||||
<RowDefinition Height="80" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Image
|
||||
x:Name="imgQrcode"
|
||||
Grid.Row="0"
|
||||
Width="300"
|
||||
Height="300"
|
||||
Width="{StaticResource QrcodeWidth}"
|
||||
Height="{StaticResource QrcodeWidth}"
|
||||
Stretch="UniformToFill" />
|
||||
|
||||
<TextBox
|
||||
x:Name="txtContent"
|
||||
Grid.Row="1"
|
||||
Width="300"
|
||||
Width="{StaticResource QrcodeWidth}"
|
||||
Margin="0,8"
|
||||
VerticalAlignment="Center"
|
||||
IsReadOnly="True"
|
||||
|
|
|
|||
Loading…
Reference in a new issue