Skip to content

Commit

Permalink
dotnet: consistently use the read.From() name and bump version to 0…
Browse files Browse the repository at this point in the history
….2.1
  • Loading branch information
axxel committed Mar 21, 2024
1 parent fc672a5 commit 75ae138
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 5 additions & 5 deletions wrappers/dotnet/ZXingCpp.DemoReader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static List<Barcode> Read(MagickImage img, ReaderOptions? opts = null)
return BarcodeReader.Read(iv, opts);
}

public static List<Barcode> Read(this BarcodeReader reader, MagickImage img) => Read(img, reader);
public static List<Barcode> From(this BarcodeReader reader, MagickImage img) => Read(img, reader);
}

public static class SkBitmapBarcodeReader
Expand All @@ -44,7 +44,7 @@ public static List<Barcode> Read(SKBitmap img, ReaderOptions? opts = null)
return BarcodeReader.Read(iv, opts);
}

public static List<Barcode> Read(this BarcodeReader reader, SKBitmap img) => Read(img, reader);
public static List<Barcode> From(this BarcodeReader reader, SKBitmap img) => Read(img, reader);
}

public class Program
Expand All @@ -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}");
}
}
12 changes: 9 additions & 3 deletions wrappers/dotnet/ZXingCpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
Expand All @@ -37,6 +37,9 @@ Executing this sample code from the command line would look like this:
dotnet run -- <image-file-name> [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
Expand All @@ -63,9 +66,12 @@ public class Program

Executing this sample code from the command line would look like this:
```sh
dotnet run -- <barcode-format> <text> <out-file-name>
dotnet run -- <barcode-format> <text> <out-svg-file-name>
```

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.
Expand Down
2 changes: 1 addition & 1 deletion wrappers/dotnet/ZXingCpp/ZXingCpp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>

<PackageId>ZXingCpp</PackageId>
<Version>0.1.3-alpha</Version>
<Version>0.2.1-alpha</Version>
<Authors>Axel Waggershauser</Authors>
<Company>zxing-cpp</Company>
<Description>
Expand Down

0 comments on commit 75ae138

Please sign in to comment.