|
1 | | -using QRCodeEncoderLibrary; |
2 | | -using System.Drawing; |
| 1 | +using System.Drawing; |
3 | 2 | using System.Drawing.Imaging; |
4 | 3 | using System.IO; |
5 | 4 | using System.Windows; |
6 | 5 | using System.Windows.Media.Imaging; |
7 | 6 | using System.Windows.Threading; |
| 7 | +using Upsilon.Apps.Passkey.Core.Utils; |
8 | 8 | using Upsilon.Apps.Passkey.GUI.WPF.Themes; |
9 | 9 | using Upsilon.Apps.Passkey.GUI.WPF.ViewModels; |
10 | 10 |
|
@@ -61,22 +61,28 @@ public static void CopyToClipboard(string text) |
61 | 61 |
|
62 | 62 | private static BitmapImage _getBitmap(string content) |
63 | 63 | { |
64 | | - QREncoder qrGenerator = new() |
65 | | - { |
66 | | - ErrorCorrection = ErrorCorrection.H |
67 | | - }; |
68 | | - bool[,] matrix = qrGenerator.Encode(content); |
| 64 | + int unit = 20; |
| 65 | + bool[,] qrCode = QrCode.Generate(content); |
| 66 | + int height = qrCode.GetLength(0); |
| 67 | + int width = qrCode.GetLength(1); |
69 | 68 |
|
70 | | - QRSaveBitmapImage qrCodeImage = new(matrix) |
71 | | - { |
72 | | - ModuleSize = 100, |
73 | | - QuietZone = 50 |
74 | | - }; |
| 69 | + Bitmap bitmap = new((height + 2) * unit, (width + 2) * unit); |
75 | 70 |
|
76 | | - MemoryStream ms = new(); |
77 | | - qrCodeImage.SaveQRCodeToImageFile(ms, ImageFormat.Bmp); |
| 71 | + using (Graphics g = Graphics.FromImage(bitmap)) |
| 72 | + { |
| 73 | + g.FillRectangle(Brushes.White, 0, 0, (height + 2) * unit, (width + 2) * unit); |
78 | 74 |
|
79 | | - Bitmap bitmap = (Bitmap)Image.FromStream(ms); |
| 75 | + for (int i = 0; i < height; i++) |
| 76 | + { |
| 77 | + for (int j = 0; j < width; j++) |
| 78 | + { |
| 79 | + if (qrCode[i, j]) |
| 80 | + { |
| 81 | + g.FillRectangle(Brushes.Black, (i + 1) * unit, (j + 1) * unit, unit, unit); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + } |
80 | 86 |
|
81 | 87 | using MemoryStream memory = new(); |
82 | 88 | bitmap.Save(memory, ImageFormat.Png); |
|
0 commit comments