From 366c1d558c414a63228d2d0f9df584dc478c2f2b Mon Sep 17 00:00:00 2001 From: Tragen Date: Wed, 29 Jun 2022 23:15:48 +0200 Subject: [PATCH 1/6] Update ArtQRCode.cs Fixed dot size calculaction --- QRCoder/ArtQRCode.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QRCoder/ArtQRCode.cs b/QRCoder/ArtQRCode.cs index c1964c93..6856f496 100644 --- a/QRCoder/ArtQRCode.cs +++ b/QRCoder/ArtQRCode.cs @@ -65,7 +65,7 @@ public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, { if (pixelSizeFactor > 1) throw new Exception("The parameter pixelSize must be between 0 and 1. (0-100%)"); - int pixelSize = (int)Math.Min(pixelsPerModule, Math.Floor(pixelsPerModule / pixelSizeFactor)); + int pixelSize = (int)Math.Min(pixelsPerModule, Math.Floor(pixelsPerModule * pixelSizeFactor)); var numModules = QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8); var offset = (drawQuietZones ? 0 : 4); @@ -295,4 +295,4 @@ public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color dark } } -#endif \ No newline at end of file +#endif From 711992105a5c871758e6b874b6e658e0862abf8d Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Wed, 17 Apr 2024 23:33:15 +0200 Subject: [PATCH 2/6] Set pixelSizeFactor default to 1.0 Changed the default to 1.0 to avoid breaking changes due to bugfix in pixelSizeFactor calculation --- QRCoder/ArtQRCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoder/ArtQRCode.cs b/QRCoder/ArtQRCode.cs index 6856f496..2667b517 100644 --- a/QRCoder/ArtQRCode.cs +++ b/QRCoder/ArtQRCode.cs @@ -59,7 +59,7 @@ public Bitmap GetGraphic(Bitmap backgroundImage = null) /// Style of the background image (if set). Fill=spanning complete graphic; DataAreaOnly=Don't paint background into quietzone /// Optional image that should be used instead of the default finder patterns /// QRCode graphic as bitmap - public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap backgroundImage = null, double pixelSizeFactor = 0.8, + public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap backgroundImage = null, double pixelSizeFactor = 1.0, bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Dotted, BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null) { From a97490cf8e1864391fed03c83b27e9b3a071ea09 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Wed, 17 Apr 2024 23:42:36 +0200 Subject: [PATCH 3/6] Fixed test cases --- QRCoderTests/ArtQRCodeRendererTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/QRCoderTests/ArtQRCodeRendererTests.cs b/QRCoderTests/ArtQRCodeRendererTests.cs index bcd32c9f..fb21c74f 100644 --- a/QRCoderTests/ArtQRCodeRendererTests.cs +++ b/QRCoderTests/ArtQRCodeRendererTests.cs @@ -99,9 +99,9 @@ public void should_throw_pixelfactor_oor_exception() [Category("QRRenderer/ArtQRCode")] public void can_instantate_parameterless() { - var asciiCode = new ArtQRCode(); - asciiCode.ShouldNotBeNull(); - asciiCode.ShouldBeOfType(); + var artCode = new ArtQRCode(); + artCode.ShouldNotBeNull(); + artCode.ShouldBeOfType(); } [Fact] @@ -115,7 +115,7 @@ public void can_render_artqrcode_from_helper() #if NET35_OR_GREATER || NET40_OR_GREATER result.ShouldBe("fea51114bc4ff893542a1c0574c82a07"); #else - result.ShouldBe("57ecaa9bdeadcdcbeac8a19d734907ff"); + result.ShouldBe("6c1bb8257349b29f76e50c3fa8abd9c9"); #endif } } From a53745ca9646987ceced68275fe083ebcadb5937 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Wed, 17 Apr 2024 23:44:44 +0200 Subject: [PATCH 4/6] Fixed tests --- QRCoderTests/ArtQRCodeRendererTests.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/QRCoderTests/ArtQRCodeRendererTests.cs b/QRCoderTests/ArtQRCodeRendererTests.cs index fb21c74f..24a06a27 100644 --- a/QRCoderTests/ArtQRCodeRendererTests.cs +++ b/QRCoderTests/ArtQRCodeRendererTests.cs @@ -112,11 +112,7 @@ public void can_render_artqrcode_from_helper() var bmp = ArtQRCodeHelper.GetQRCode("A", 10, Color.Black, Color.White, Color.Transparent, QRCodeGenerator.ECCLevel.L); var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("fea51114bc4ff893542a1c0574c82a07"); -#else result.ShouldBe("6c1bb8257349b29f76e50c3fa8abd9c9"); -#endif } } } From 8d7dde85c1c8dee6f8f2036e71b796405145483d Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Thu, 18 Apr 2024 00:01:27 +0200 Subject: [PATCH 5/6] Set default to 1.0 in helper function --- QRCoder/ArtQRCode.cs | 4 ++-- QRCoderTests/ArtQRCodeRendererTests.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/QRCoder/ArtQRCode.cs b/QRCoder/ArtQRCode.cs index 2667b517..79a2eddc 100644 --- a/QRCoder/ArtQRCode.cs +++ b/QRCoder/ArtQRCode.cs @@ -59,7 +59,7 @@ public Bitmap GetGraphic(Bitmap backgroundImage = null) /// Style of the background image (if set). Fill=spanning complete graphic; DataAreaOnly=Don't paint background into quietzone /// Optional image that should be used instead of the default finder patterns /// QRCode graphic as bitmap - public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap backgroundImage = null, double pixelSizeFactor = 1.0, + public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap backgroundImage = null, double pixelSizeFactor = 1, bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Dotted, BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null) { @@ -283,7 +283,7 @@ public static class ArtQRCodeHelper /// Optional image that should be used instead of the default finder patterns /// QRCode graphic as bitmap public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, ECCLevel eccLevel, bool forceUtf8 = false, - bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 0.8, + bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 1.0, bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Flat, BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null) { diff --git a/QRCoderTests/ArtQRCodeRendererTests.cs b/QRCoderTests/ArtQRCodeRendererTests.cs index 24a06a27..8bfcc029 100644 --- a/QRCoderTests/ArtQRCodeRendererTests.cs +++ b/QRCoderTests/ArtQRCodeRendererTests.cs @@ -6,6 +6,7 @@ using System.Drawing; using QRCoderTests.Helpers.XUnitExtenstions; using QRCoderTests.Helpers; +using System.Drawing.Imaging; namespace QRCoderTests { @@ -110,9 +111,9 @@ public void can_render_artqrcode_from_helper() { //Create QR code var bmp = ArtQRCodeHelper.GetQRCode("A", 10, Color.Black, Color.White, Color.Transparent, QRCodeGenerator.ECCLevel.L); - + ((Bitmap)bmp.Clone()).Save("C:\\Users\\netbl\\Downloads\\art_new.png", ImageFormat.Png); var result = HelperFunctions.BitmapToHash(bmp); - result.ShouldBe("6c1bb8257349b29f76e50c3fa8abd9c9"); + result.ShouldBe("57ecaa9bdeadcdcbeac8a19d734907ff"); } } } From 871e70adc718879e13f4d93229a05c794d1d6b19 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Thu, 18 Apr 2024 00:04:04 +0200 Subject: [PATCH 6/6] Cleaned test cases --- QRCoderTests/ArtQRCodeRendererTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/QRCoderTests/ArtQRCodeRendererTests.cs b/QRCoderTests/ArtQRCodeRendererTests.cs index 8bfcc029..9742bb3a 100644 --- a/QRCoderTests/ArtQRCodeRendererTests.cs +++ b/QRCoderTests/ArtQRCodeRendererTests.cs @@ -6,7 +6,6 @@ using System.Drawing; using QRCoderTests.Helpers.XUnitExtenstions; using QRCoderTests.Helpers; -using System.Drawing.Imaging; namespace QRCoderTests { @@ -111,7 +110,6 @@ public void can_render_artqrcode_from_helper() { //Create QR code var bmp = ArtQRCodeHelper.GetQRCode("A", 10, Color.Black, Color.White, Color.Transparent, QRCodeGenerator.ECCLevel.L); - ((Bitmap)bmp.Clone()).Save("C:\\Users\\netbl\\Downloads\\art_new.png", ImageFormat.Png); var result = HelperFunctions.BitmapToHash(bmp); result.ShouldBe("57ecaa9bdeadcdcbeac8a19d734907ff"); }