From 75ae138c7a9d29effd767c046c615000a3a09be9 Mon Sep 17 00:00:00 2001 From: axxel Date: Thu, 21 Mar 2024 10:03:37 +0100 Subject: [PATCH] dotnet: consistently use the `read.From()` name and bump version to 0.2.1 --- wrappers/dotnet/ZXingCpp.DemoReader/Program.cs | 10 +++++----- wrappers/dotnet/ZXingCpp/README.md | 12 +++++++++--- wrappers/dotnet/ZXingCpp/ZXingCpp.csproj | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/wrappers/dotnet/ZXingCpp.DemoReader/Program.cs b/wrappers/dotnet/ZXingCpp.DemoReader/Program.cs index 52372f5f88..6b111444d1 100644 --- a/wrappers/dotnet/ZXingCpp.DemoReader/Program.cs +++ b/wrappers/dotnet/ZXingCpp.DemoReader/Program.cs @@ -19,7 +19,7 @@ public static List Read(MagickImage img, ReaderOptions? opts = null) return BarcodeReader.Read(iv, opts); } - public static List Read(this BarcodeReader reader, MagickImage img) => Read(img, reader); + public static List From(this BarcodeReader reader, MagickImage img) => Read(img, reader); } public static class SkBitmapBarcodeReader @@ -44,7 +44,7 @@ public static List Read(SKBitmap img, ReaderOptions? opts = null) return BarcodeReader.Read(iv, opts); } - public static List Read(this BarcodeReader reader, SKBitmap img) => Read(img, reader); + public static List From(this BarcodeReader reader, SKBitmap img) => Read(img, reader); } public class Program @@ -58,15 +58,15 @@ public static void Main(string[] args) #endif Console.WriteLine(img); - var reader = new BarcodeReader() { + var readBarcodes = new BarcodeReader() { TryInvert = false, ReturnErrors = true, }; if (args.Length >= 2) - reader.Formats = Barcode.FormatsFromString(args[1]); + readBarcodes.Formats = Barcode.FormatsFromString(args[1]); - foreach (var b in reader.Read(img)) + foreach (var b in readBarcodes.From(img)) Console.WriteLine($"{b.Format} ({b.ContentType}): {b.Text} / [{string.Join(", ", b.Bytes)}] {b.ErrorMsg}"); } } diff --git a/wrappers/dotnet/ZXingCpp/README.md b/wrappers/dotnet/ZXingCpp/README.md index fdd01e6d7e..98194c3a37 100644 --- a/wrappers/dotnet/ZXingCpp/README.md +++ b/wrappers/dotnet/ZXingCpp/README.md @@ -20,13 +20,13 @@ public class Program var img = SKBitmap.Decode(args[0]).Copy(SKColorType.Gray8); var iv = new ImageView(img.GetPixels(), img.Info.Width, img.Info.Height, ImageFormat.Lum); - var reader = new BarcodeReader() { + var readBarcodes = new BarcodeReader() { Formats = args.Length > 1 ? Barcode.FormatsFromString(args[1]) : BarcodeFormats.Any, TryInvert = false, // see the ReaderOptions implementation for more available options }; - foreach (var b in reader.Read(iv)) + foreach (var b in readBarcodes.From(iv)) Console.WriteLine($"{b.Format} : {b.Text}"); } } @@ -37,6 +37,9 @@ Executing this sample code from the command line would look like this: dotnet run -- [barcode-format-list] ``` +See also the [ZXingCpp.DemoReader](https://github.com/zxing-cpp/zxing-cpp/blob/master/wrappers/dotnet/ZXingCpp.DemoReader/Program.cs) +which shows the use of extension classes to support SkiaSharp and ImageMagick based input. + The NuGet package includes the runtime/native c++ libraries for the x64 architecture on Windows, Linux and macOS. If something is not working out of the box or you need arm64 support then you need to build the `[lib]ZXing[.dll|.so|.dylib]` file yourself and make sure the .NET @@ -63,9 +66,12 @@ public class Program Executing this sample code from the command line would look like this: ```sh -dotnet run -- +dotnet run -- ``` +For an example how to write a PNG file instead of a SVG file, have a look at the +[ZXingCpp.DemoWriter](https://github.com/zxing-cpp/zxing-cpp/blob/master/wrappers/dotnet/ZXingCpp.DemoWriter/Program.cs). + ## Why ZXingCpp? There are a number of areas where ZXingCpp shines compared to other popular .NET barcode scanner libraries. diff --git a/wrappers/dotnet/ZXingCpp/ZXingCpp.csproj b/wrappers/dotnet/ZXingCpp/ZXingCpp.csproj index f55757cf37..395feade5b 100644 --- a/wrappers/dotnet/ZXingCpp/ZXingCpp.csproj +++ b/wrappers/dotnet/ZXingCpp/ZXingCpp.csproj @@ -6,7 +6,7 @@ enable ZXingCpp - 0.1.3-alpha + 0.2.1-alpha Axel Waggershauser zxing-cpp