From 76ad789e1c8519de6f3aaf1f976744b5ec93fee0 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Thu, 25 Jan 2024 10:06:53 +0400 Subject: [PATCH] feat: Added QrCodes.System.Drawing library. --- QrCodes.sln | 7 + README.md | 27 +- sample/DynamicExamplePage.xaml | 9 + src/libs/QrCodes.Maui/QrCodeSource.cs | 2 + src/libs/QrCodes.Maui/QrCodes.Maui.csproj | 3 - .../Renderers/SkiaSharpRenderer.cs | 81 ++++-- .../QrCodes.System.Drawing.csproj | 21 ++ .../Renderers/ImageExtensions.cs | 80 ++++++ .../Renderers/SystemDrawingRenderer.cs | 254 ++++++++++++++++++ .../Renderers/Abstractions/BackgroundType.cs | 5 + .../Renderers/Abstractions/FileFormat.cs | 10 +- .../Abstractions/RendererSettings.cs | 5 + 12 files changed, 463 insertions(+), 41 deletions(-) create mode 100644 src/libs/QrCodes.System.Drawing/QrCodes.System.Drawing.csproj create mode 100644 src/libs/QrCodes.System.Drawing/Renderers/ImageExtensions.cs create mode 100644 src/libs/QrCodes.System.Drawing/Renderers/SystemDrawingRenderer.cs diff --git a/QrCodes.sln b/QrCodes.sln index 12ff9d2..ccad339 100644 --- a/QrCodes.sln +++ b/QrCodes.sln @@ -42,6 +42,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QrCodes.Benchmarks", "src\b EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QrCodes.SkiaSharp", "src\libs\QrCodes.SkiaSharp\QrCodes.SkiaSharp.csproj", "{DCBD2245-73F4-4644-AD0C-38D8197BABB4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QrCodes.System.Drawing", "src\libs\QrCodes.System.Drawing\QrCodes.System.Drawing.csproj", "{F58F57D4-B95E-42BF-9BA3-16A31C9E9831}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -76,6 +78,10 @@ Global {DCBD2245-73F4-4644-AD0C-38D8197BABB4}.Debug|Any CPU.Build.0 = Debug|Any CPU {DCBD2245-73F4-4644-AD0C-38D8197BABB4}.Release|Any CPU.ActiveCfg = Release|Any CPU {DCBD2245-73F4-4644-AD0C-38D8197BABB4}.Release|Any CPU.Build.0 = Release|Any CPU + {F58F57D4-B95E-42BF-9BA3-16A31C9E9831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F58F57D4-B95E-42BF-9BA3-16A31C9E9831}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F58F57D4-B95E-42BF-9BA3-16A31C9E9831}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F58F57D4-B95E-42BF-9BA3-16A31C9E9831}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -89,6 +95,7 @@ Global {594FD49C-F7AC-44EC-98D7-788E83D6260D} = {928D4422-05CE-4AC2-89B0-31060889AE6A} {507C686B-CBB2-4559-8FCC-DBFA90B3E987} = {732F539D-3402-4E31-AD43-F3653C9F2F0C} {DCBD2245-73F4-4644-AD0C-38D8197BABB4} = {928D4422-05CE-4AC2-89B0-31060889AE6A} + {F58F57D4-B95E-42BF-9BA3-16A31C9E9831} = {928D4422-05CE-4AC2-89B0-31060889AE6A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1493AEE4-9211-46E9-BFE6-8F629EAC5693} diff --git a/README.md b/README.md index 0d59da9..154517e 100644 --- a/README.md +++ b/README.md @@ -44,28 +44,31 @@ It contains various payloads and framework helpers for MAUI. ### Usage ``` -// Base library with all payloads and some renderers(Ascii, Base64, Bitmap, PNG, SVG, PostScript) +// Base library with all payloads and some renderers(Ascii, Base64, Pdf, FastBitmap, FastPng, SVG, PostScript) dotnet add package QrCodes -// ImageSharpRenderer(Gif, Jpeg, Png, WebP, Bmp, Pbm, Tga, Tiff), Export to PDF -dotnet add package QrCodes.ImageSharp -// SkiaSharpRenderer(Gif, Jpeg, Png, WebP, Bmp, Ico, Wbmp, Pkm, Ktx, Astc, Dng, Heif, Avif), Export to PDF + +// SkiaSharpRenderer(Gif, Jpeg, Png, WebP, Bmp, Ico, Wbmp, Pkm, Ktx, Astc, Dng, Heif, Avif) +dotnet add package QrCodes.SkiaSharp +// ImageSharpRenderer(Gif, Jpeg, Png, WebP, Bmp, Pbm, Tga, Tiff) dotnet add package QrCodes.ImageSharp +// SystemDrawingRenderer(Gif, Jpeg, Png, Bmp, Tiff) +dotnet add package QrCodes.System.Drawing + // MAUI helpers(QrCodeSource and QrCodeExtension markup extension). Uses SkiaSharpRenderer. dotnet add package QrCodes.Maui ``` -#### Generate QR code with logo image +#### Generate QR code ```csharp var qrCode = QrCodeGenerator.Generate( plainText: new Telegram(user: "havendv").ToString(), eccLevel: ErrorCorrectionLevel.High); -using var image = SkiaSharpRenderer.Render( - data: qrCode, - pixelsPerModule: 5, - darkColor: Color.Black, - lightColor: Color.White, - drawQuietZones: false); -var bytes = image.ToBytes(FileFormat.Png); +using var pngBytes = SkiaSharpRenderer.RenderToBytes( + data, + settings: new RendererSettings + { + DarkColor = Color.Red, + }); ``` #### Generate ImageSource for MAUI diff --git a/sample/DynamicExamplePage.xaml b/sample/DynamicExamplePage.xaml index 2b50aa9..3c00c5c 100644 --- a/sample/DynamicExamplePage.xaml +++ b/sample/DynamicExamplePage.xaml @@ -136,6 +136,13 @@ x:Name="BackgroundTypePicker" ItemsSource="{qr:Enum Type={x:Type renderers:BackgroundType}}" SelectedItem="{x:Static renderers:BackgroundType.Circle}" /> +