Barcode2DImageReader Class

Provides methods to read the Data Matrix, PDF417 and Aztec symbols of an image.

public static class Barcode2DImageReader

Methods

NameDescription
ReadBarcodes2D(Image, Barcode2DReadingOptions?, CancellationToken)Reads the Data Matrix, PDF417 and Aztec symbols of an image.

ReadBarcodes2D(Image, Barcode2DReadingOptions?, CancellationToken)

Barcode2DImageReader.cs

Reads 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

image Image
The image. For an animated image, its first frame is read.
options Barcode2DReadingOptions?
The reading options, or null for the defaults.
cancellationToken CancellationToken
A token to cancel the reading.

Returns

IReadOnlyList<Barcode2DImageResult> The symbols found, each once; empty when there is none.

Exceptions

ArgumentNullException
image is null.
OperationCanceledException
cancellationToken was 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));