|
| 1 | +## About |
| 2 | +A library which supports decoding and generating of barcodes (like QR Code, PDF 417, EAN, UPC, Aztec, Data Matrix, Codabar) within images. |
| 3 | + |
| 4 | +## How to Use |
| 5 | +The source code repository includes small examples for Windows Forms, Silverlight, Windows Phone and other project types. |
| 6 | + |
| 7 | +The following example works with the classic .Net framework until version 4.8.1: |
| 8 | + |
| 9 | +```csharp |
| 10 | +// create a barcode reader instance |
| 11 | +IBarcodeReader reader = new BarcodeReader(); |
| 12 | +// load a bitmap |
| 13 | +var barcodeBitmap = (Bitmap)Image.FromFile("C:\\sample-barcode-image.png"); |
| 14 | +// detect and decode the barcode inside the bitmap |
| 15 | +var result = reader.Decode(barcodeBitmap); |
| 16 | +// do something with the result |
| 17 | +if (result != null) |
| 18 | +{ |
| 19 | + txtDecoderType.Text = result.BarcodeFormat.ToString(); |
| 20 | + txtDecoderContent.Text = result.Text; |
| 21 | +} |
| 22 | +``` |
| 23 | +If you want to try the sample code above within a project which target .Net Standard or .Net 5.0 or higher then you have to add one of the |
| 24 | +additional nuget package for a specific image library: https://www.nuget.org/packages?q=ZXing.Bindings |
| 25 | +The main package of ZXing.Net for such platforms only contains the core classes which are not dependent on a specific assembly for image formats. |
| 26 | + |
| 27 | +```csharp |
| 28 | +// example shows a simple decoding snippet as a .Net 8.0 console appliation which uses the ZXing.Windows.Compatibility package |
| 29 | +using System.Drawing; |
| 30 | +using ZXing.Windows.Compatibility; |
| 31 | + |
| 32 | +// create a barcode reader instance |
| 33 | +var reader = new BarcodeReader(); |
| 34 | +// load a bitmap |
| 35 | +var barcodeBitmap = (Bitmap)Image.FromFile("C:\\sample-barcode-image.png"); |
| 36 | +// detect and decode the barcode inside the bitmap |
| 37 | +var result = reader.Decode(barcodeBitmap); |
| 38 | +// do something with the result |
| 39 | +if (result != null) |
| 40 | +{ |
| 41 | + Console.WriteLine(result.BarcodeFormat.ToString()); |
| 42 | + Console.WriteLine(result.Text); |
| 43 | +} |
| 44 | +else |
| 45 | +{ |
| 46 | + Console.WriteLine("No barcode found"); |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +## Related Packages |
| 51 | +There are several packages which can be used with different image libraries in combination with ZXing.Net. |
| 52 | +https://www.nuget.org/packages?q=ZXing.Bindings |
| 53 | + |
| 54 | +## Feedback |
| 55 | +Bug reports and contributions are welcome at [the GitHub repository](https://github.com/micjahn/ZXing.Net). |
0 commit comments