Skip to content

Commit

Permalink
dotnet: split README into repo and NuGet versions
Browse files Browse the repository at this point in the history
  • Loading branch information
axxel committed Feb 2, 2024
1 parent c580d1e commit e6fb84b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 49 deletions.
51 changes: 4 additions & 47 deletions wrappers/dotnet/README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,21 @@
# ZXingCpp

ZXingCpp is a .NET wrapper for the C++ library [zxing-cpp](https://github.com/zxing-cpp/zxing-cpp).

It is an open-source, multi-format linear/matrix barcode image processing library implemented in C++.
It was originally ported from the Java ZXing Library but has been developed further and now includes
many improvements in terms of runtime and detection performance.

## Usage
ZXingCpp is a .NET wrapper for [zxing-cpp](https://github.com/zxing-cpp/zxing-cpp).

There is a NuGet package available: https://www.nuget.org/packages/ZXingCpp. It does currently not yet
contain the native binary dll file. That needs to be copied/build separately at the moment.

Simple example usage:

```cs
using System.Collections.Generic;
using ImageMagick;
using ZXingCpp;

public static class MagickImageBarcodeReader
{
public static List<Barcode> Read(MagickImage img, ReaderOptions? opts = null)
{
if (img.DetermineBitDepth() < 8)
img.SetBitDepth(8);
var bytes = img.ToByteArray(MagickFormat.Gray);
var iv = new ImageView(bytes, img.Width, img.Height, ImageFormat.Lum);
return BarcodeReader.Read(iv, opts);
}

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

public class Program
{
public static void Main(string[] args)
{
var img = new MagickImage(args[0]);
## Usage

var reader = new BarcodeReader() {
Formats = BarcodeReader.FormatsFromString(args[1]),
TryInvert = false,
};

foreach (var b in reader.Read(img))
Console.WriteLine($"{b.Format} : {b.Text}");
}
}
```
See either the [ZXingCpp/README.md](ZXingCpp/README.md) or the [ZXingCpp.Demo](ZXingCpp.Demo) project.

To run the `ZXingCpp.Demo` sample program, it is important that the dotnet runtime finds the native
`ZXing[.dll|.so|.dylib]` in your path. E.g. on Linux a complete command line would look like this

```sh
LD_LIBRARY_PATH=<path-to-your-ZXing.so> dotnet run --project ZXingCpp.Demo -- ../../test/samples/multi-1/1.png
LD_LIBRARY_PATH=<ZXing.so-path> dotnet run --project ZXingCpp.Demo -- ../../test/samples/multi-1/1.png
```

Note: This should currently be considered a pre-release. The API may change slightly to be even more
"managed" depending on community feedback.

## Benchmarking

To compare the performance of this .NET wrapper project with other available barcode scanner .NET libraries,
Expand Down
64 changes: 64 additions & 0 deletions wrappers/dotnet/ZXingCpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ZXingCpp

ZXingCpp is a .NET wrapper for the C++ library [zxing-cpp](https://github.com/zxing-cpp/zxing-cpp).

It is an open-source, multi-format linear/matrix barcode image processing library implemented in C++.
It was originally ported from the Java ZXing Library but has been developed further and now includes
many improvements in terms of runtime and detection performance.

## Usage

```cs
using System.Collections.Generic;
using ImageMagick;
using ZXingCpp;

// BarcodeReader extension class to support direct reading from MagickImage
public static class MagickImageBarcodeReader
{
public static List<Barcode> Read(MagickImage img, ReaderOptions? opts = null)
{
if (img.DetermineBitDepth() < 8)
img.SetBitDepth(8);
var bytes = img.ToByteArray(MagickFormat.Gray);
var iv = new ImageView(bytes, img.Width, img.Height, ImageFormat.Lum);
return BarcodeReader.Read(iv, opts);
}

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

public class Program
{
public static void Main(string[] args)
{
var img = new MagickImage(args[0]);

var reader = new BarcodeReader() {
Formats = BarcodeReader.FormatsFromString(args[1]),
TryInvert = false,
// see the ReaderOptions implementation for more available options
};

foreach (var b in reader.Read(img))
Console.WriteLine($"{b.Format} : {b.Text}");
}
}
```

To run the code above, it is important that the dotnet runtime finds the native
`ZXing[.dll|.so|.dylib]` in your path. E.g. on Linux a complete command line would look like this

```sh
LD_LIBRARY_PATH=<ZXing.so-path> dotnet run -- <image-file-name>
```

Note: This is an alpha release, meaning the API may still change slightly to feel even more
"managed" depending on community feedback.

## Benchmarking

To compare the performance of this .NET wrapper project with other available barcode scanner .NET libraries,
I started the project [zxing-bench](https://github.com/axxel/zxing-bench).
The [README](https://github.com/axxel/zxing-bench/blob/main/dotnet/README.md) contains a few results to get an idea.
4 changes: 2 additions & 2 deletions 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.1-alpha</Version>
<Version>0.1.2-alpha</Version>
<Authors>Axel Waggershauser</Authors>
<Company>zxing-cpp</Company>
<Description>
Expand All @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="README.md"/>
<None Include="README.md" Pack="true" PackagePath="README.md"/>
</ItemGroup>
</Project>

Expand Down

0 comments on commit e6fb84b

Please sign in to comment.