Table of Contents

Class BarcodeModules

Namespace
Egami.Barcodes
Assembly
Egami.Barcodes.dll

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

int

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

bool

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

x int

The column, from 0 at the left.

y int

The row, from 0 at the top.

Property Value

bool

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

ReadOnlySpan<int>

Width

Gets the width in modules.

public int Width { get; }

Property Value

int

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

width int

The width in modules.

height int

The height in modules.

modules ReadOnlySpan<bool>

true for each dark module; width times height values.

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

runs ReadOnlySpan<int>

The widths in modules, in turn bar, space, bar and so on, starting and ending with a bar.

height int

The 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.