Barcode2DImageReader Class
Provides methods to read the Data Matrix, PDF417 and Aztec symbols of an image.
public static class Barcode2DImageReaderMethods
| Name | Description |
|---|---|
| ReadBarcodes2D(Image, Barcode2DReadingOptions?, CancellationToken) | Reads the Data Matrix, PDF417 and Aztec symbols of an image. |
ReadBarcodes2D(Image, Barcode2DReadingOptions?, CancellationToken)
Barcode2DImageReader.csReads the Data Matrix, PDF417 and Aztec symbols of an image.
public static IReadOnlyList<Barcode2DImageResult> ReadBarcodes2D(this Image image, Barcode2DReadingOptions? options = null, CancellationToken cancellationToken = default)Parameters
imageImage- The image. For an animated image, its first frame is read.
optionsBarcode2DReadingOptions?- The reading options, or
nullfor the defaults. cancellationTokenCancellationToken- A token to cancel the reading.
Returns
IReadOnlyList<Barcode2DImageResult> The symbols found, each once; empty when there is none.
Exceptions
ArgumentNullExceptionimageisnull.OperationCanceledExceptioncancellationTokenwas canceled.
Remarks
The reader is made for clean images: generated, printed or scanned symbols, photographed straight on. It finds the solid sides of the finder pattern of a Data Matrix symbol, the bullseye of an Aztec symbol and the start and stop patterns of the rows of a PDF417 symbol, samples their modules and decodes them with Barcode2DDecoder. Data Matrix and Aztec symbols can be rotated or mirrored; the rows of a PDF417 symbol must be about horizontal or vertical. A transparent background reads as white.
A symbol needs its quiet zone and modules of at least 2 pixels. The pixels are classified as dark or light with the Otsu threshold of the image, then with a local threshold (Sauvola) when no symbol is found.
Example
using var image = Barcode2D.CreateDataMatrix("https://www.meziantou.net").ToImage(); // or Image.Load("label.png")
var results = image.ReadBarcodes2D();
var result = Assert.Single(results);
Assert.Equal((Barcode2DType.DataMatrix, "https://www.meziantou.net"), (result.Result.Type, result.Text));