diff --git a/ZXing.Net.MAUI/Apple/BarcodeBitmapRenderer.ios.maccatalyst.cs b/ZXing.Net.MAUI/Apple/BarcodeBitmapRenderer.ios.maccatalyst.cs
index 57b5646..eecb196 100644
--- a/ZXing.Net.MAUI/Apple/BarcodeBitmapRenderer.ios.maccatalyst.cs
+++ b/ZXing.Net.MAUI/Apple/BarcodeBitmapRenderer.ios.maccatalyst.cs
@@ -3,6 +3,8 @@
using Microsoft.Maui.Graphics.Platform;
using MauiColor = Microsoft.Maui.Graphics.Color;
using ZXing.Common;
+using System.Threading;
+
#if IOS || MACCATALYST
using Foundation;
@@ -42,24 +44,40 @@ public UIImage Render(BitMatrix matrix, ZXing.BarcodeFormat format, string conte
public UIImage Render(BitMatrix matrix, ZXing.BarcodeFormat format, string content, EncodingOptions options)
{
- UIGraphics.BeginImageContext(new CGSize(matrix.Width, matrix.Height));
- var context = UIGraphics.GetCurrentContext();
+ var renderer = new UIGraphicsImageRenderer(new CGSize(matrix.Width, matrix.Height), new UIGraphicsImageRendererFormat {
+ Opaque = false,
+ Scale = UIScreen.MainScreen.Scale
+ });
- for (var x = 0; x < matrix.Width; x++)
+ var waiter = new ManualResetEvent(false);
+ UIImage image = null!;
+
+ renderer.CreateImage(context =>
{
- for (var y = 0; y < matrix.Height; y++)
+ var black = new CGColor(0f, 0f, 0f);
+ var white = new CGColor(1.0f, 1.0f, 1.0f);
+
+ for (var x = 0; x < matrix.Width; x++)
{
- context.SetFillColor(matrix[x, y] ? ForegroundColor : BackgroundColor);
- context.FillRect(new CGRect(x, y, 1, 1));
+ for (var y = 0; y < matrix.Height; y++)
+ {
+ context.CGContext.SetFillColor(matrix[x, y] ? black : white);
+ context.CGContext.FillRect(new CGRect(x, y, 1, 1));
+ }
}
- }
-
- var img = UIGraphics.GetImageFromCurrentImageContext();
+
+ SetImage(context.CurrentImage);
+ });
- UIGraphics.EndImageContext();
-
- return img;
+ waiter.WaitOne();
+ return image;
+
+ void SetImage(UIImage img)
+ {
+ image = img;
+ waiter.Set();
+ }
}
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/ZXing.Net.MAUI/ZXing.Net.MAUI.csproj b/ZXing.Net.MAUI/ZXing.Net.MAUI.csproj
index 0e0bbed..6b0698d 100644
--- a/ZXing.Net.MAUI/ZXing.Net.MAUI.csproj
+++ b/ZXing.Net.MAUI/ZXing.Net.MAUI.csproj
@@ -23,9 +23,9 @@
true
-
-
-
+
+
+