From fe3836be142ee5372a41568bf3439b8e913408b4 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 19 Oct 2024 14:29:53 +0800 Subject: [PATCH] Bug fix QRCodeHelper --- v2rayN/v2rayN/Common/QRCodeHelper.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/v2rayN/v2rayN/Common/QRCodeHelper.cs b/v2rayN/v2rayN/Common/QRCodeHelper.cs index ff8c8833..e677037a 100644 --- a/v2rayN/v2rayN/Common/QRCodeHelper.cs +++ b/v2rayN/v2rayN/Common/QRCodeHelper.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System.Collections; +using System.Drawing; using System.IO; using System.Windows; using System.Windows.Interop; @@ -7,9 +8,6 @@ using System.Windows.Media.Imaging; namespace v2rayN { - /// - /// 含有QR码的描述类和包装编码和渲染 - /// public class QRCodeHelper { public static ImageSource? GetQRCode(string? strContent) @@ -62,21 +60,14 @@ namespace v2rayN y = 96 / g.DpiY; } - private static ImageSource ByteToImage(byte[] imageData) + private static ImageSource? ByteToImage(IEnumerable imageData) { - BitmapImage biImg = new(); - using MemoryStream ms = new(imageData); - biImg.BeginInit(); - biImg.StreamSource = ms; - biImg.EndInit(); - - return biImg as ImageSource; + return new ImageSourceConverter().ConvertFrom(imageData) as BitmapSource; } private static byte[]? ImageToByte(Image img) { - var converter = new ImageConverter(); - return converter.ConvertTo(img, typeof(byte[])) as byte[]; + return new ImageConverter().ConvertTo(img, typeof(byte[])) as byte[]; } } } \ No newline at end of file