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 reads generated, printed and scanned images, and photographs. 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, mirrored, blurred, unevenly lit or in perspective: the edges of a Data Matrix symbol and the corners of the bullseye of an Aztec symbol give the perspective. 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 a local threshold (from the blocks of 8x8 pixels around them, which follows shadows and gradients), then with the Otsu threshold of the image and a Sauvola threshold 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));