Barcode2DDecoder Class

Reads the data of Data Matrix (ECC 200), PDF417 and Aztec symbols from their modules, with error correction.

public static class Barcode2DDecoder

Remarks

The decoder works on modules, not on pixels. To read the symbols of an image, use the ReadBarcodes2D methods of the Meziantou.Framework.Imaging.Barcodes package, which locate the symbols and sample their modules.

A Data Matrix or Aztec symbol can be in any orientation, mirrored included: the decoder finds it from the finder pattern. The rows of a PDF417 symbol can be read from either side, and each row of the symbol can span several rows of the matrix, as Barcode2D draws them.

Methods

NameDescription
Decode(Barcode2D)Reads the data of a symbol.
Decode(bool[,], Barcode2DType)Reads the data of a symbol from its modules.
TryDecode(bool[,], Barcode2DType, Barcode2DDecodeResult?)Tries to read the data of a symbol from its modules.

Decode overloads

Decode(Barcode2D)

Barcode2DDecoder.cs

Reads the data of a symbol.

public static Barcode2DDecodeResult Decode(Barcode2D barcode)
Parameters
barcode Barcode2D
The symbol.
Returns

Barcode2DDecodeResult The content of the symbol.

Exceptions
ArgumentNullException
barcode is null.
Example
var dataMatrix = Barcode2D.CreateDataMatrix("https://www.meziantou.net");

var result = Barcode2DDecoder.Decode(dataMatrix);

Assert.Equal("https://www.meziantou.net", result.Text);
Assert.Equal(Barcode2DType.DataMatrix, result.Type);

Decode(bool[,], Barcode2DType)

Barcode2DDecoder.cs

Reads the data of a symbol from its modules.

public static Barcode2DDecodeResult Decode(bool[,] modules, Barcode2DType type)
Parameters
modules bool[,]
The modules, true for dark, indexed by row then column, without quiet zone.
type Barcode2DType
The type of the symbol.
Returns

Barcode2DDecodeResult The content of the symbol.

Exceptions
ArgumentNullException
modules is null.
ArgumentOutOfRangeException
type is not a value of Barcode2DType.
FormatException
The modules are not a symbol of the type, or have more errors than the error correction can fix.

TryDecode(bool[,], Barcode2DType, Barcode2DDecodeResult?)

Barcode2DDecoder.cs

Tries to read the data of a symbol from its modules.

public static bool TryDecode(bool[,] modules, Barcode2DType type, out Barcode2DDecodeResult? result)

Parameters

modules bool[,]
The modules, true for dark, indexed by row then column, without quiet zone.
type Barcode2DType
The type of the symbol.
result Barcode2DDecodeResult?
When this method returns true, the content of the symbol.

Returns

bool true if the modules are a symbol that could be read; otherwise, false.

Exceptions

ArgumentNullException
modules is null.
ArgumentOutOfRangeException
type is not a value of Barcode2DType.