Table of Contents

Class BarcodeReader

Namespace
Egami.Barcodes
Assembly
Egami.Barcodes.dll

Reads barcodes from images: raster.ReadBarcodes() finds every symbol, raster.ReadBarcode() the first. The reader is thread-safe and allocates per call only.

public static class BarcodeReader
Inheritance
BarcodeReader
Inherited Members

Examples

// Every barcode in the image, of any format.
foreach (BarcodeResult result in scan.ReadBarcodes())
{
    Console.WriteLine($"{result.Format}: {result.Text} at {result.Corners[0]}");
}

Methods

ReadBarcode(ReadOnlySpan<byte>, int, int, int, BarcodeReaderOptions?)

Finds and decodes the first barcode in an 8-bit luminance buffer, such as a camera frame's Y plane, without copying it.

public static BarcodeResult? ReadBarcode(ReadOnlySpan<byte> luminance, int width, int height, int stride, BarcodeReaderOptions? options = null)

Parameters

luminance ReadOnlySpan<byte>

The pixels, 0 black to 255 white, row by row.

width int

The width in pixels.

height int

The height in pixels.

stride int

The bytes from one row's start to the next's, at least width.

options BarcodeReaderOptions

The formats, effort and region, or null for Default.

Returns

BarcodeResult

The barcode, or null when there is none.

Examples

// A camera frame's Y plane (8-bit luminance, rows padded to the stride), read in place.
BarcodeResult? code = BarcodeReader.ReadBarcode(yPlane, width, height, stride);

Exceptions

ArgumentOutOfRangeException

The size or stride is not positive, or the stride is less than the width.

ArgumentException

The buffer is too short for the size and stride.

ReadBarcode<TPixel>(Raster<TPixel>, BarcodeReaderOptions?)

Finds and decodes the first barcode of the allowed formats in an image.

public static BarcodeResult? ReadBarcode<TPixel>(this Raster<TPixel> raster, BarcodeReaderOptions? options = null) where TPixel : unmanaged, IPixelType<TPixel>

Parameters

raster Raster<TPixel>

The image.

options BarcodeReaderOptions

The formats, effort and region, or null for Default.

Returns

BarcodeResult

The barcode, or null when there is none.

Type Parameters

TPixel

The pixel type; any is converted to luminance first.

Examples

// Only the formats you expect, searched harder; a rendered barcode can skip the search.
BarcodeResult? result = label.ReadBarcode(new BarcodeReaderOptions
{
    Formats = BarcodeFormat.DataMatrix | BarcodeFormat.Qr,
    Effort = 7,
});

if (result?.Gs1 is { } elements)
{
    foreach (Gs1ElementString element in elements)
    {
        Console.WriteLine($"{element.Title}: {element.Value}");
    }
}

BarcodeResult? rendered = label.ReadBarcode(new BarcodeReaderOptions { PureBarcode = true });

ReadBarcodes(ReadOnlySpan<byte>, int, int, int, BarcodeReaderOptions?)

Finds and decodes every barcode in an 8-bit luminance buffer, such as a camera frame's Y plane, without copying it.

public static IReadOnlyList<BarcodeResult> ReadBarcodes(ReadOnlySpan<byte> luminance, int width, int height, int stride, BarcodeReaderOptions? options = null)

Parameters

luminance ReadOnlySpan<byte>

The pixels, 0 black to 255 white, row by row.

width int

The width in pixels.

height int

The height in pixels.

stride int

The bytes from one row's start to the next's, at least width.

options BarcodeReaderOptions

The formats, effort and region, or null for Default.

Returns

IReadOnlyList<BarcodeResult>

The barcodes found, in reading order (top to bottom, then left to right); empty when there are none.

Examples

// A camera frame's Y plane (8-bit luminance, rows padded to the stride), read in place.
BarcodeResult? code = BarcodeReader.ReadBarcode(yPlane, width, height, stride);

Exceptions

ArgumentOutOfRangeException

The size or stride is not positive, or the stride is less than the width.

ArgumentException

The buffer is too short for the size and stride.

ReadBarcodes<TPixel>(Raster<TPixel>, BarcodeReaderOptions?)

Finds and decodes every barcode of the allowed formats in an image.

public static IReadOnlyList<BarcodeResult> ReadBarcodes<TPixel>(this Raster<TPixel> raster, BarcodeReaderOptions? options = null) where TPixel : unmanaged, IPixelType<TPixel>

Parameters

raster Raster<TPixel>

The image.

options BarcodeReaderOptions

The formats, effort and region, or null for Default.

Returns

IReadOnlyList<BarcodeResult>

The barcodes found, in reading order (top to bottom, then left to right); empty when there are none.

Type Parameters

TPixel

The pixel type; any is converted to luminance first.

Examples

// Every barcode in the image, of any format.
foreach (BarcodeResult result in scan.ReadBarcodes())
{
    Console.WriteLine($"{result.Format}: {result.Text} at {result.Corners[0]}");
}