Barcode2D Class

Represents a generated two-dimensional barcode (Data Matrix, PDF417 or Aztec) as a boolean matrix of modules.

public sealed class Barcode2D

Remarks

A text made of ASCII characters only (U+0000 to U+007F) is encoded as it is. Another text is encoded as UTF-8, preceded by the ECI designator of UTF-8 (assignment number 26), so that readers do not decode its bytes with the default character set of the symbology. Binary data is encoded as it is, without an ECI designator.

The modules are square. The rows of a PDF417 symbol are taller than its modules are wide: each row of the symbol is Pdf417Options.RowHeight rows of the matrix.

Properties

NameDescription
HeightGets the height (number of rows), quiet zone excluded.
TypeGets the type of barcode.
WidthGets the width (number of columns), quiet zone excluded.

Gets the height (number of rows), quiet zone excluded.

public int Height { get; }

Property value

int

Gets the type of barcode.

public Barcode2DType Type { get; }

Property value

Barcode2DType

Gets the width (number of columns), quiet zone excluded.

public int Width { get; }

Property value

int

Indexers

NameDescription
this[int, int]Gets whether the module at the specified position is dark.

this[int, int]

Barcode2D.cs

Gets whether the module at the specified position is dark.

public bool this[int row, int column] { get; }

Parameters

row int
The row index (0-based).
column int
The column index (0-based).

Property value

bool

Methods

NameDescription
CreateAztec(ReadOnlySpan<byte>, AztecOptions?)Creates an Aztec symbol from the specified binary data.
CreateAztec(string, AztecOptions?)Creates an Aztec symbol from the specified text.
CreateDataMatrix(ReadOnlySpan<byte>, DataMatrixOptions?)Creates a Data Matrix (ECC 200) symbol from the specified binary data.
CreateDataMatrix(string, DataMatrixOptions?)Creates a Data Matrix (ECC 200) symbol from the specified text.
CreateGs1DataMatrix(ReadOnlySpan<Gs1Element>)Creates a GS1 Data Matrix symbol from GS1 element strings.
CreateGs1DataMatrix(ReadOnlySpan<Gs1Element>, DataMatrixOptions?)Creates a GS1 Data Matrix symbol from GS1 element strings.
CreatePdf417(ReadOnlySpan<byte>, Pdf417Options?)Creates a PDF417 symbol from the specified binary data.
CreatePdf417(string, Pdf417Options?)Creates a PDF417 symbol from the specified text.

CreateAztec overloads

CreateAztec(ReadOnlySpan<byte>, AztecOptions?)

Barcode2D.cs

Creates an Aztec symbol from the specified binary data.

public static Barcode2D CreateAztec(ReadOnlySpan<byte> data, AztecOptions? options = null)
Parameters
data ReadOnlySpan<byte>
The bytes to encode.
options AztecOptions?
The options, or null for the defaults: the smallest compact or full-range symbol that holds the data with 23% of error correction.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentException
data is empty, or AztecOptions.Layers is greater than 4 for a compact symbol.
InvalidOperationException
The data does not fit in the largest allowed size.

CreateAztec(string, AztecOptions?)

Barcode2D.cs

Creates an Aztec symbol from the specified text.

public static Barcode2D CreateAztec(string data, AztecOptions? options = null)
Parameters
data string
The text to encode.
options AztecOptions?
The options, or null for the defaults: the smallest compact or full-range symbol that holds the data with 23% of error correction.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentNullException
data is null.
ArgumentException
data is empty, or AztecOptions.Layers is greater than 4 for a compact symbol.
InvalidOperationException
The data does not fit in the largest allowed size.

CreateDataMatrix overloads

CreateDataMatrix(ReadOnlySpan<byte>, DataMatrixOptions?)

Barcode2D.cs

Creates a Data Matrix (ECC 200) symbol from the specified binary data.

public static Barcode2D CreateDataMatrix(ReadOnlySpan<byte> data, DataMatrixOptions? options = null)
Parameters
data ReadOnlySpan<byte>
The bytes to encode.
options DataMatrixOptions?
The options, or null for the defaults: the smallest square symbol that holds the data.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentException
data is empty, or no Data Matrix size satisfies the constraints of options.
InvalidOperationException
The data does not fit in the largest allowed size.

CreateDataMatrix(string, DataMatrixOptions?)

Barcode2D.cs

Creates a Data Matrix (ECC 200) symbol from the specified text.

public static Barcode2D CreateDataMatrix(string data, DataMatrixOptions? options = null)
Parameters
data string
The text to encode.
options DataMatrixOptions?
The options, or null for the defaults: the smallest square symbol that holds the data.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentNullException
data is null.
ArgumentException
data is empty, or no Data Matrix size satisfies the constraints of options.
InvalidOperationException
The data does not fit in the largest allowed size.

CreateGs1DataMatrix overloads

CreateGs1DataMatrix(ReadOnlySpan<Gs1Element>)

Barcode2D.cs

Creates a GS1 Data Matrix symbol from GS1 element strings.

public static Barcode2D CreateGs1DataMatrix(params scoped ReadOnlySpan<Gs1Element> elements)
Parameters
elements ReadOnlySpan<Gs1Element>
The element strings, in the order they are encoded.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentException
elements is empty or contains null.
InvalidOperationException
The data does not fit in the largest Data Matrix symbol.
Remarks

The symbol starts with the FNC1 function character that identifies GS1 Data Matrix, and a FNC1 separator follows each element whose application identifier does not have a predefined length, except the last one. A reader returns the data with the separators as the ASCII group separator character (U+001D) and the symbology identifier ]d2.

CreateGs1DataMatrix(ReadOnlySpan<Gs1Element>, DataMatrixOptions?)

Barcode2D.cs

Creates a GS1 Data Matrix symbol from GS1 element strings.

public static Barcode2D CreateGs1DataMatrix(ReadOnlySpan<Gs1Element> elements, DataMatrixOptions? options)
Parameters
elements ReadOnlySpan<Gs1Element>
The element strings, in the order they are encoded.
options DataMatrixOptions?
The options, or null for the defaults: the smallest square symbol that holds the data.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentException
elements is empty or contains null, or no Data Matrix size satisfies the constraints of options.
InvalidOperationException
The data does not fit in the largest allowed size.
Remarks

The symbol starts with the FNC1 function character that identifies GS1 Data Matrix, and a FNC1 separator follows each element whose application identifier does not have a predefined length, except the last one. A reader returns the data with the separators as the ASCII group separator character (U+001D) and the symbology identifier ]d2.

CreatePdf417 overloads

CreatePdf417(ReadOnlySpan<byte>, Pdf417Options?)

Barcode2D.cs

Creates a PDF417 symbol from the specified binary data.

public static Barcode2D CreatePdf417(ReadOnlySpan<byte> data, Pdf417Options? options = null)
Parameters
data ReadOnlySpan<byte>
The bytes to encode.
options Pdf417Options?
The options, or null for the defaults: the error correction level recommended for the data length, and a number of columns chosen for the data.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentException
data is empty.
InvalidOperationException
The data does not fit in a PDF417 symbol with the constraints of options.

CreatePdf417(string, Pdf417Options?)

Barcode2D.cs

Creates a PDF417 symbol from the specified text.

public static Barcode2D CreatePdf417(string data, Pdf417Options? options = null)
Parameters
data string
The text to encode.
options Pdf417Options?
The options, or null for the defaults: the error correction level recommended for the data length, and a number of columns chosen for the data.
Returns

Barcode2D A new Barcode2D instance.

Exceptions
ArgumentNullException
data is null.
ArgumentException
data is empty.
InvalidOperationException
The data does not fit in a PDF417 symbol with the constraints of options.