Class BarcodeModules
The modules of a barcode symbol: a grid of dark and light squares for a 2D symbol, or a row of bars and spaces for a linear one. Every encoder ends in one, and drawing, rasterizing and path building work from it. It holds the symbol only, without its quiet zone. A grid is immutable and safe to read from many threads.
public sealed class BarcodeModules
- Inheritance
-
BarcodeModules
- Inherited Members
Examples
// A 2D grid, row by row from the top; true is a dark module.
BarcodeModules grid = BarcodeModules.Create(3, 3,
[
true, false, true,
false, true, false,
true, false, true,
]);
// A linear symbol: bar and space widths in modules, starting and ending with a bar.
BarcodeModules bars = BarcodeModules.CreateLinear([2, 1, 1, 1, 3], height: 20);
for (int y = 0; y < grid.Height; y++)
{
for (int x = 0; x < grid.Width; x++)
{
Console.Write(grid[x, y] ? '#' : '.');
}
Console.WriteLine();
}
Console.WriteLine($"{bars.Width} modules wide, bars {string.Join(' ', bars.Runs.ToArray())}");
Properties
Height
Gets the height in modules; for a linear symbol, the height of its bars.
public int Height { get; }
Property Value
IsLinear
Gets a value indicating whether this is a linear symbol, whose columns are all dark or all light.
public bool IsLinear { get; }
Property Value
this[int, int]
Gets a value indicating whether the module at a column and row is dark.
public bool this[int x, int y] { get; }
Parameters
Property Value
Exceptions
- ArgumentOutOfRangeException
The module is outside the symbol.
Runs
Gets the widths of a linear symbol's bars and spaces in modules, in turn from its first bar, or an empty span for a 2D symbol.
public ReadOnlySpan<int> Runs { get; }
Property Value
Width
Gets the width in modules.
public int Width { get; }
Property Value
Methods
Create(int, int, ReadOnlySpan<bool>)
Makes a 2D grid from its modules, row by row from the top.
public static BarcodeModules Create(int width, int height, ReadOnlySpan<bool> modules)
Parameters
widthintThe width in modules.
heightintThe height in modules.
modulesReadOnlySpan<bool>true for each dark module;
widthtimesheightvalues.
Returns
- BarcodeModules
The grid, which keeps its own copy of the modules.
Exceptions
- ArgumentOutOfRangeException
The width or height is not positive.
- ArgumentException
The number of modules is not the width times the height.
CreateLinear(ReadOnlySpan<int>, int)
Makes a linear symbol from the widths of its bars and spaces.
public static BarcodeModules CreateLinear(ReadOnlySpan<int> runs, int height)
Parameters
runsReadOnlySpan<int>The widths in modules, in turn bar, space, bar and so on, starting and ending with a bar.
heightintThe height of the bars in modules.
Returns
- BarcodeModules
The symbol.
Exceptions
- ArgumentOutOfRangeException
The height is not positive.
- ArgumentException
There is no run, a run is not positive, or the last run is a space.