From 8f6214671ce431f1bd59488b23803fa0d14da144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mierzyn=CC=81ski?= Date: Mon, 25 Feb 2019 09:26:11 +0100 Subject: [PATCH 1/2] Fixed the problem with barcode rendering upside down on macOS --- Source/ZXing.Net.Mobile.macOS/BitmapRenderer.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/ZXing.Net.Mobile.macOS/BitmapRenderer.cs b/Source/ZXing.Net.Mobile.macOS/BitmapRenderer.cs index b953c2760..7f8288cae 100644 --- a/Source/ZXing.Net.Mobile.macOS/BitmapRenderer.cs +++ b/Source/ZXing.Net.Mobile.macOS/BitmapRenderer.cs @@ -1,18 +1,13 @@ using System; using ZXing.Rendering; - -using Foundation; -using CoreFoundation; using CoreGraphics; using AppKit; - using ZXing.Common; namespace ZXing.Mobile { public class BitmapRenderer : IBarcodeRenderer { - public NSImage Render(BitMatrix matrix, BarcodeFormat format, string content) { return Render(matrix, format, content, new EncodingOptions()); @@ -25,11 +20,12 @@ public NSImage Render(BitMatrix matrix, BarcodeFormat format, string content, En var black = new CGColor(0f, 0f, 0f); var white = new CGColor(1.0f, 1.0f, 1.0f); - for (int x = 0; x < matrix.Width; x++) + for (var x = 0; x < matrix.Width; x++) { - for (int y = 0; y < matrix.Height; y++) + for (var y = 0; y < matrix.Height; y++) { - context.SetFillColor(matrix[x, y] ? black : white); + var (cgX, cgY) = TransformToCoreGraphicsCoords(x, y, matrix); + context.SetFillColor(matrix[cgX, cgY] ? black : white); context.FillRect(new CGRect(x, y, 1, 1)); } } @@ -39,5 +35,10 @@ public NSImage Render(BitMatrix matrix, BarcodeFormat format, string content, En return img; } + + private static (int cgX, int cgY) TransformToCoreGraphicsCoords(int x, int y, BitMatrix matrix) + { + return (x, Math.Abs(y - matrix.Height + 1)); + } } } From 1d1a1d9f632e47cd5ed990ab6a38f794d8241c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mierzyn=CC=81ski?= Date: Mon, 25 Feb 2019 09:26:48 +0100 Subject: [PATCH 2/2] Changed minimum os version for macOS sample --- Samples/macOS/Sample.macOS/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Samples/macOS/Sample.macOS/Info.plist b/Samples/macOS/Sample.macOS/Info.plist index 5ff82decb..9629bb950 100644 --- a/Samples/macOS/Sample.macOS/Info.plist +++ b/Samples/macOS/Sample.macOS/Info.plist @@ -11,7 +11,7 @@ CFBundleVersion 1 LSMinimumSystemVersion - 10.14 + 10.13 CFBundleDevelopmentRegion en CFBundleInfoDictionaryVersion