Class Barcode
A barcode symbol: its format, its modules, the quiet zone its standard asks for and the human-readable text that goes with it. It draws on any canvas as vector paths (CanvasBarcodeExtensions), becomes one Path, or renders to a raster with whole-pixel modules. A barcode is immutable and safe to use from many threads.
public sealed class Barcode
- Inheritance
-
Barcode
- Inherited Members
Examples
// Modules from another encoder become a barcode with the quiet zone of their standard: 4 modules for QR.
Barcode qr = Barcode.FromModules(BarcodeFormat.Qr, modules);
Console.WriteLine($"{qr.Format}: {qr.Modules.Width} modules plus {qr.QuietZone} on each side");
Properties
Format
Gets the symbology.
public BarcodeFormat Format { get; }
Property Value
HumanReadableText
public string? HumanReadableText { get; }
Property Value
Modules
Gets the symbol's modules, without the quiet zone.
public BarcodeModules Modules { get; }
Property Value
QuietZone
Gets the width of the clear margin readers need around the symbol, in modules: 4 for QR, 1 for Data Matrix, 2 for PDF417 and 0 for Aztec; at each end of a linear symbol, 10 for Code 128, Code 39 and ITF, 11 for EAN-13, 7 for EAN-8 and 9 for UPC-A and UPC-E.
public int QuietZone { get; }
Property Value
Methods
Aztec(ReadOnlySpan<byte>, AztecOptions?)
Makes an Aztec Code from bytes, without an ECI.
public static Barcode Aztec(ReadOnlySpan<byte> data, AztecOptions? options = null)
Parameters
dataReadOnlySpan<byte>The bytes.
optionsAztecOptionsThe error correction share, compact form and layers, or null for Default.
Returns
- Barcode
The barcode, with no human-readable text.
Examples
// The smallest compact or full-range symbol with at least 23 % error correction; no quiet zone needed.
Barcode ticket = Barcode.Aztec("EG1234 BER-MUC 2026-10-19 SEAT 12A DOE/JANE");
// More error correction for a ticket that gets folded, or a fixed compact size.
Barcode robust = Barcode.Aztec("EG1234 BER-MUC", new AztecOptions { ErrorCorrectionPercent = 50 });
Barcode compact = Barcode.Aztec("EG1234", new AztecOptions { Compact = true, Layers = 2 });
// A rune: one value from 0 to 255 in an 11 x 11 core.
Barcode rune = Barcode.AztecRune(42);
Exceptions
- ArgumentException
There are no bytes, or they do not fit in a symbol.
Aztec(string, AztecOptions?)
Makes an Aztec Code (ISO/IEC 24778) from text, as on rail and airline tickets. The text is written in the modes that give the fewest bits; text in ISO 8859-1 is written as it is, other text as UTF-8 with ECI 26. Aztec needs no quiet zone.
public static Barcode Aztec(string text, AztecOptions? options = null)
Parameters
textstringThe text.
optionsAztecOptionsThe error correction share, compact form and layers, or null for Default.
Returns
- Barcode
The barcode.
Examples
// The smallest compact or full-range symbol with at least 23 % error correction; no quiet zone needed.
Barcode ticket = Barcode.Aztec("EG1234 BER-MUC 2026-10-19 SEAT 12A DOE/JANE");
// More error correction for a ticket that gets folded, or a fixed compact size.
Barcode robust = Barcode.Aztec("EG1234 BER-MUC", new AztecOptions { ErrorCorrectionPercent = 50 });
Barcode compact = Barcode.Aztec("EG1234", new AztecOptions { Compact = true, Layers = 2 });
// A rune: one value from 0 to 255 in an 11 x 11 core.
Barcode rune = Barcode.AztecRune(42);
Exceptions
- ArgumentException
The text is empty or does not fit in a symbol.
AztecRune(int)
Makes an Aztec Rune: an 11 x 11 core that holds one value, 0 to 255, for machine-readable marks.
public static Barcode AztecRune(int value)
Parameters
valueintThe value.
Returns
- Barcode
The barcode.
Exceptions
- ArgumentOutOfRangeException
The value is not 0 to 255.
Code128(string, Code128Options?)
Makes a Code 128 barcode (ISO/IEC 15417). The code sets A, B and C, and the changes and shifts between them, are picked to give the shortest symbol; runs of digits go in pairs in code set C. Characters 128 to 255 (ISO 8859-1) take an FNC4 each.
public static Barcode Code128(string text, Code128Options? options = null)
Parameters
textstringThe text, of characters 0 to 255.
optionsCode128Options
Returns
- Barcode
The barcode, with the text as its human-readable text (control characters shown as spaces).
Examples
// The shortest mix of code sets A, B and C; the digits go in pairs.
Barcode code = Barcode.Code128("ORDER-1180042", new Code128Options { Height = 40 });
using Raster<Gray8> image = code.ToRaster(pixelsPerModule: 2);
Exceptions
- ArgumentException
The text is empty, longer than 1000 characters, or has a character above 255.
Code39(string, Code39Options?)
Makes a Code 39 barcode (ISO/IEC 16388): digits, capital letters, space and - . $ / + %. Other ASCII characters are
written as Full ASCII pairs when FullAscii allows it.
public static Barcode Code39(string text, Code39Options? options = null)
Parameters
textstringThe text.
optionsCode39OptionsThe check character, Full ASCII, wide ratio and height, or null for Default.
Returns
- Barcode
The barcode, with the text (and a check character, when there is one and the text is not Full ASCII) as its human-readable text.
Examples
// Capitals, digits and a few symbols; lowercase switches to Full ASCII on its own.
Barcode part = Barcode.Code39("PART-0042", new Code39Options { CheckDigit = true });
Console.WriteLine(part.HumanReadableText); // PART-0042 and its mod 43 check character
Exceptions
- ArgumentException
The text is empty, longer than 1000 characters, or has a character Code 39 cannot hold.
Create(BarcodeFormat, string)
Makes a barcode of a format chosen at run time, with that format's default options, for callers that store the format with the data. It calls the format's own factory, such as Qr(string, QrOptions?) or Ean13(string, EanUpcOptions?).
public static Barcode Create(BarcodeFormat format, string text)
Parameters
formatBarcodeFormatThe symbology.
textstringThe text or digits.
Returns
- Barcode
The barcode.
Examples
// Labels from a table that stores each barcode's format with its data.
(BarcodeFormat Format, string Data)[] rows =
[
(BarcodeFormat.Ean13, "590123412345"),
(BarcodeFormat.Code128, "SHIP-0042"),
(BarcodeFormat.Qr, "https://inexin.github.io/Egami/"),
];
foreach ((BarcodeFormat format, string data) in rows)
{
Barcode barcode = Barcode.Create(format, data);
using Raster<Gray8> image = barcode.ToRaster(pixelsPerModule: 3);
}
Exceptions
- ArgumentOutOfRangeException
formatis not a BarcodeFormat.- ArgumentException
The text does not suit the format or does not fit in a symbol.
DataMatrix(IReadOnlyList<Gs1ElementString>, DataMatrixOptions?)
Makes a GS1 Data Matrix symbol: FNC1 first and the element strings, separated by FNC1 where their AIs need it.
public static Barcode DataMatrix(IReadOnlyList<Gs1ElementString> elements, DataMatrixOptions? options = null)
Parameters
elementsIReadOnlyList<Gs1ElementString>The element strings, from Parse(string).
optionsDataMatrixOptions
Returns
- Barcode
The barcode, with the element strings in their human-readable form as its text.
Examples
// Square by default; the encodation modes are switched for the fewest codewords.
Barcode part = Barcode.DataMatrix("PN 4711-0815 / LOT 2026-10");
// A narrow label: rectangular sizes, the DMRE ones too.
Barcode narrow = Barcode.DataMatrix("PN 4711-0815 / LOT 2026-10", new DataMatrixOptions
{
Shape = DataMatrixShape.Rectangle,
AllowDmre = true,
});
// GS1 Data Matrix, as on medicine packs.
Barcode pack = Barcode.DataMatrix(Gs1.Parse("(01)09501101530003(17)261231(10)AB12(21)XYZ"));
Exceptions
- ArgumentException
There are no element strings, or they do not fit in the largest allowed symbol.
DataMatrix(ReadOnlySpan<byte>, DataMatrixOptions?)
Makes a Data Matrix symbol from bytes, without an ECI.
public static Barcode DataMatrix(ReadOnlySpan<byte> data, DataMatrixOptions? options = null)
Parameters
dataReadOnlySpan<byte>The bytes, at most 3116.
optionsDataMatrixOptions
Returns
- Barcode
The barcode, with no human-readable text.
Examples
// Square by default; the encodation modes are switched for the fewest codewords.
Barcode part = Barcode.DataMatrix("PN 4711-0815 / LOT 2026-10");
// A narrow label: rectangular sizes, the DMRE ones too.
Barcode narrow = Barcode.DataMatrix("PN 4711-0815 / LOT 2026-10", new DataMatrixOptions
{
Shape = DataMatrixShape.Rectangle,
AllowDmre = true,
});
// GS1 Data Matrix, as on medicine packs.
Barcode pack = Barcode.DataMatrix(Gs1.Parse("(01)09501101530003(17)261231(10)AB12(21)XYZ"));
Exceptions
- ArgumentException
There are no bytes, or they do not fit in the largest allowed symbol.
DataMatrix(string, DataMatrixOptions?)
Makes a Data Matrix ECC 200 symbol (ISO/IEC 16022) from text. The six encodation modes are switched for the fewest codewords. Text in ISO 8859-1 is written as it is; other text is written as UTF-8 with ECI 26 before it.
public static Barcode DataMatrix(string text, DataMatrixOptions? options = null)
Parameters
textstringThe text, at most 3116 characters.
optionsDataMatrixOptions
Returns
- Barcode
The barcode.
Examples
// Square by default; the encodation modes are switched for the fewest codewords.
Barcode part = Barcode.DataMatrix("PN 4711-0815 / LOT 2026-10");
// A narrow label: rectangular sizes, the DMRE ones too.
Barcode narrow = Barcode.DataMatrix("PN 4711-0815 / LOT 2026-10", new DataMatrixOptions
{
Shape = DataMatrixShape.Rectangle,
AllowDmre = true,
});
// GS1 Data Matrix, as on medicine packs.
Barcode pack = Barcode.DataMatrix(Gs1.Parse("(01)09501101530003(17)261231(10)AB12(21)XYZ"));
Exceptions
- ArgumentException
The text is empty or does not fit in the largest allowed symbol.
Ean13(string, EanUpcOptions?)
Makes an EAN-13 barcode (ISO/IEC 15420), such as a GTIN-13 or an ISBN. Twelve digits get their check digit added; thirteen are checked. With a Font, the first digit is drawn left of the symbol and the others between the guard bars, which reach down into the text line.
public static Barcode Ean13(string digits, EanUpcOptions? options = null)
Parameters
digitsstring12 or 13 digits.
optionsEanUpcOptions
Returns
- Barcode
The barcode, with the 13 digits (and the add-on after a space) as its human-readable text.
Examples
// A book: the ISBN as EAN-13, its check digit added, and the price as an EAN-5 add-on.
Barcode book = Barcode.Ean13("978020137962", new EanUpcOptions { AddOn = "52495" });
// Fitted into a rectangle, with the digits between the guard bars.
using Raster<Rgba8> label = Raster.Create(400, 200, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = label.CreateCanvas())
{
canvas.DrawBarcode(book, new RectF(10, 10, 380, 180), Rgba8.Black, new BarcodeDrawOptions { Font = font });
}
// A UPC-A number written in its short UPC-E form.
Barcode small = Barcode.UpcE("042100005264");
Exceptions
- ArgumentException
The text is not 12 or 13 digits, or the check digit is wrong.
Ean8(string, EanUpcOptions?)
Makes an EAN-8 barcode (ISO/IEC 15420) for small packages. Seven digits get their check digit added; eight are checked.
public static Barcode Ean8(string digits, EanUpcOptions? options = null)
Parameters
digitsstring7 or 8 digits.
optionsEanUpcOptions
Returns
- Barcode
The barcode, with the 8 digits (and the add-on after a space) as its human-readable text.
Examples
// A book: the ISBN as EAN-13, its check digit added, and the price as an EAN-5 add-on.
Barcode book = Barcode.Ean13("978020137962", new EanUpcOptions { AddOn = "52495" });
// Fitted into a rectangle, with the digits between the guard bars.
using Raster<Rgba8> label = Raster.Create(400, 200, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = label.CreateCanvas())
{
canvas.DrawBarcode(book, new RectF(10, 10, 380, 180), Rgba8.Black, new BarcodeDrawOptions { Font = font });
}
// A UPC-A number written in its short UPC-E form.
Barcode small = Barcode.UpcE("042100005264");
Exceptions
- ArgumentException
The text is not 7 or 8 digits, or the check digit is wrong.
FromModules(BarcodeFormat, BarcodeModules, string?)
Makes a barcode from modules you already have, with the quiet zone of its format's standard.
public static Barcode FromModules(BarcodeFormat format, BarcodeModules modules, string? humanReadableText = null)
Parameters
formatBarcodeFormatThe symbology the modules are.
modulesBarcodeModulesThe modules: a linear symbol for the linear formats, a 2D grid for the others.
humanReadableTextstringThe text to print under the symbol, or null.
Returns
- Barcode
The barcode.
Exceptions
- ArgumentOutOfRangeException
formatis not a BarcodeFormat.- ArgumentException
The modules are linear for a 2D format, or a 2D grid for a linear one.
Gs1Code128(IReadOnlyList<Gs1ElementString>, Code128Options?)
Makes a GS1-128 barcode: Code 128 with FNC1 first and the element strings after it, an FNC1 after each one whose AI has no predefined length unless it is the last.
public static Barcode Gs1Code128(IReadOnlyList<Gs1ElementString> elements, Code128Options? options = null)
Parameters
elementsIReadOnlyList<Gs1ElementString>The element strings, from Parse(string) or Create(string, string).
optionsCode128Options
Returns
- Barcode
The barcode, with the element strings in their human-readable form as its text.
Examples
// Each element string is checked: the AI, the length, the GTIN's check digit, the date.
IReadOnlyList<Gs1ElementString> elements = Gs1.Parse("(01)09501101530003(17)261231(10)AB12");
Barcode label = Barcode.Gs1Code128(elements);
// Mistakes say what is wrong.
if (!Gs1.TryParse("(01)09501101530004", out _))
{
Console.WriteLine("(01) has a wrong check digit");
}
Exceptions
- ArgumentException
There are no element strings, or more than 1000 characters.
Gs1Code128(string, Code128Options?)
Makes a GS1-128 barcode from element strings in their human-readable form, such as (01)09501101530003(10)AB12.
public static Barcode Gs1Code128(string elements, Code128Options? options = null)
Parameters
elementsstringThe element strings, each AI in parentheses; see Parse(string).
optionsCode128Options
Returns
- Barcode
The barcode.
Examples
// Each element string is checked: the AI, the length, the GTIN's check digit, the date.
IReadOnlyList<Gs1ElementString> elements = Gs1.Parse("(01)09501101530003(17)261231(10)AB12");
Barcode label = Barcode.Gs1Code128(elements);
// Mistakes say what is wrong.
if (!Gs1.TryParse("(01)09501101530004", out _))
{
Console.WriteLine("(01) has a wrong check digit");
}
Exceptions
- FormatException
The text is not valid element strings; the message says which and how.
- ArgumentException
There are more than 1000 characters.
Itf(string, ItfOptions?)
Makes an Interleaved 2 of 5 barcode (ISO/IEC 16390) from digits; an odd number of digits gets a leading zero, as the symbology holds pairs.
public static Barcode Itf(string digits, ItfOptions? options = null)
Parameters
digitsstringThe digits.
optionsItfOptionsThe wide ratio, bearer bars and height, or null for Default.
Returns
- Barcode
The barcode, with the digits it holds as its human-readable text.
Examples
// A GTIN-14 on a carton: the check digit is added, and bearer bars frame the symbol.
Barcode carton = Barcode.Itf14("1540014128876");
using Raster<Gray8> image = carton.ToRaster(pixelsPerModule: 3);
// Plain Interleaved 2 of 5 with a 2:1 wide ratio and no bearers.
Barcode itf = Barcode.Itf("0123456789", new ItfOptions { WideRatio = 2 });
Exceptions
- ArgumentException
The text is empty, longer than 1000 characters, or has a character that is not a digit.
Itf14(string, ItfOptions?)
Makes an ITF-14 barcode (GS1): a GTIN-14 as Interleaved 2 of 5, framed by bearer bars. Thirteen digits get their check digit added; fourteen are checked.
public static Barcode Itf14(string digits, ItfOptions? options = null)
Parameters
digitsstring13 or 14 digits.
optionsItfOptionsThe wide ratio, bearer bars and height, or null for Default.
Returns
- Barcode
The barcode, with the 14 digits as its human-readable text.
Examples
// A GTIN-14 on a carton: the check digit is added, and bearer bars frame the symbol.
Barcode carton = Barcode.Itf14("1540014128876");
using Raster<Gray8> image = carton.ToRaster(pixelsPerModule: 3);
// Plain Interleaved 2 of 5 with a 2:1 wide ratio and no bearers.
Barcode itf = Barcode.Itf("0123456789", new ItfOptions { WideRatio = 2 });
Exceptions
- ArgumentException
The text is not 13 or 14 digits, or the check digit is wrong.
Pdf417(ReadOnlySpan<byte>, Pdf417Options?)
Makes a PDF417 symbol from bytes, without an ECI.
public static Barcode Pdf417(ReadOnlySpan<byte> data, Pdf417Options? options = null)
Parameters
dataReadOnlySpan<byte>The bytes.
optionsPdf417OptionsThe columns, error level and compact form, or null for Default.
Returns
- Barcode
The barcode, with no human-readable text.
Examples
// About three times as wide as tall, error level from the standard's table for the amount of data.
Barcode ticket = Barcode.Pdf417("PASSENGER DOE/JANE FLIGHT EG1234 SEAT 12A GATE B17");
// Six data columns and error level 5, or the compact form for a narrow space.
Barcode wide = Barcode.Pdf417("PASSENGER DOE/JANE", new Pdf417Options { Columns = 6, ErrorLevel = 5 });
Barcode compact = Barcode.Pdf417("PASSENGER DOE/JANE", new Pdf417Options { Compact = true });
Exceptions
- ArgumentException
There are no bytes, or they do not fit in a symbol.
Pdf417(string, Pdf417Options?)
Makes a PDF417 symbol (ISO/IEC 15438) from text, in text, numeric and byte compaction chosen run by run. Text in ISO 8859-1 is written as it is; other text is written as UTF-8 with ECI 26 before it. Each row is 3 modules tall.
public static Barcode Pdf417(string text, Pdf417Options? options = null)
Parameters
textstringThe text.
optionsPdf417OptionsThe columns, error level and compact form, or null for Default.
Returns
- Barcode
The barcode.
Examples
// About three times as wide as tall, error level from the standard's table for the amount of data.
Barcode ticket = Barcode.Pdf417("PASSENGER DOE/JANE FLIGHT EG1234 SEAT 12A GATE B17");
// Six data columns and error level 5, or the compact form for a narrow space.
Barcode wide = Barcode.Pdf417("PASSENGER DOE/JANE", new Pdf417Options { Columns = 6, ErrorLevel = 5 });
Barcode compact = Barcode.Pdf417("PASSENGER DOE/JANE", new Pdf417Options { Compact = true });
Exceptions
- ArgumentException
The text is empty or does not fit in a symbol.
Qr(IReadOnlyList<Gs1ElementString>, QrOptions?)
Makes a GS1 QR Code: FNC1 in first position and the element strings after it, separated where their AIs need it.
public static Barcode Qr(IReadOnlyList<Gs1ElementString> elements, QrOptions? options = null)
Parameters
elementsIReadOnlyList<Gs1ElementString>The element strings, from Parse(string).
optionsQrOptions
Returns
- Barcode
The barcode, with the element strings in their human-readable form as its text.
Examples
// Level M, raised to Q or H when that fits in the same size; segments chosen for the fewest bits.
Barcode link = Barcode.Qr("https://inexin.github.io/Egami/");
// A fixed size and level, for a layout that must not change.
Barcode fixedSize = Barcode.Qr("ORDER-1180042", new QrOptions { Version = 3, ErrorCorrection = QrErrorCorrection.H });
// Bytes as they are, and GS1 element strings with FNC1.
Barcode bytes = Barcode.Qr([0x45, 0x67, 0x61, 0x6D, 0x69]);
Barcode gs1 = Barcode.Qr(Gs1.Parse("(01)09501101530003(10)AB12"));
using Raster<Gray8> image = link.ToRaster(pixelsPerModule: 4);
Exceptions
- ArgumentException
There are no element strings, or they do not fit in the symbol.
Qr(ReadOnlySpan<byte>, QrOptions?)
Makes a QR Code from bytes, written in byte mode (and numeric and alphanumeric where shorter) without an ECI.
public static Barcode Qr(ReadOnlySpan<byte> data, QrOptions? options = null)
Parameters
dataReadOnlySpan<byte>The bytes.
optionsQrOptions
Returns
- Barcode
The barcode, with no human-readable text.
Examples
// Level M, raised to Q or H when that fits in the same size; segments chosen for the fewest bits.
Barcode link = Barcode.Qr("https://inexin.github.io/Egami/");
// A fixed size and level, for a layout that must not change.
Barcode fixedSize = Barcode.Qr("ORDER-1180042", new QrOptions { Version = 3, ErrorCorrection = QrErrorCorrection.H });
// Bytes as they are, and GS1 element strings with FNC1.
Barcode bytes = Barcode.Qr([0x45, 0x67, 0x61, 0x6D, 0x69]);
Barcode gs1 = Barcode.Qr(Gs1.Parse("(01)09501101530003(10)AB12"));
using Raster<Gray8> image = link.ToRaster(pixelsPerModule: 4);
Exceptions
- ArgumentException
There are no bytes, or they do not fit in the symbol.
Qr(string, QrOptions?)
Makes a QR Code (ISO/IEC 18004) from text. The text is split into numeric, alphanumeric, byte and Kanji segments that give the fewest bits. Text in ISO 8859-1 is written as it is; text that Shift JIS holds is written in Shift JIS, its kanji in Kanji mode; other text is written as UTF-8 with ECI 26 before it.
public static Barcode Qr(string text, QrOptions? options = null)
Parameters
textstringThe text.
optionsQrOptionsThe level, version and mask, or null for Default: level M, raised while it fits.
Returns
- Barcode
The barcode.
Examples
// Level M, raised to Q or H when that fits in the same size; segments chosen for the fewest bits.
Barcode link = Barcode.Qr("https://inexin.github.io/Egami/");
// A fixed size and level, for a layout that must not change.
Barcode fixedSize = Barcode.Qr("ORDER-1180042", new QrOptions { Version = 3, ErrorCorrection = QrErrorCorrection.H });
// Bytes as they are, and GS1 element strings with FNC1.
Barcode bytes = Barcode.Qr([0x45, 0x67, 0x61, 0x6D, 0x69]);
Barcode gs1 = Barcode.Qr(Gs1.Parse("(01)09501101530003(10)AB12"));
using Raster<Gray8> image = link.ToRaster(pixelsPerModule: 4);
Exceptions
- ArgumentException
The text is empty or does not fit in the symbol.
ToPath(float, BarcodeDrawOptions?)
Returns the symbol as one path: a rectangle per run of dark modules in a row, all filled with the nonzero rule. The quiet zone's top-left corner is at the origin, so with the quiet zone on the symbol starts at QuietZone modules in. Linear bars are Height modules tall. No text is included.
public Path ToPath(float moduleSize = 1, BarcodeDrawOptions? options = null)
Parameters
moduleSizefloatThe width of a module in path units; 1 by default.
optionsBarcodeDrawOptionsThe quiet zone and bar width reduction, or null for Default.
Returns
- Path
The path.
Examples
// One path, a rectangle per run of dark modules; the quiet zone's corner is at the origin.
Path path = qr.ToPath(moduleSize: 4);
string svg = path.ToSvg();
Exceptions
- ArgumentOutOfRangeException
moduleSizeis not positive and finite.
ToRaster(int, BarcodeDrawOptions?)
Renders the symbol black on white, each module a square of whole pixels, with the quiet zone around it and, when Font is set, the human-readable text under it. Linear bars are Height modules tall.
public Raster<Gray8> ToRaster(int pixelsPerModule = 1, BarcodeDrawOptions? options = null)
Parameters
pixelsPerModuleintThe width of a module in pixels; 1 by default.
optionsBarcodeDrawOptionsThe quiet zone, bar width reduction (rounded to whole pixels) and font, or null for Default.
Returns
Examples
// Black on white, 4 pixels a module, quiet zone included.
using Raster<Gray8> image = qr.ToRaster(pixelsPerModule: 4);
Exceptions
- ArgumentOutOfRangeException
pixelsPerModuleis not positive, or the raster would be too large.
UpcA(string, EanUpcOptions?)
Makes a UPC-A barcode (ISO/IEC 15420). Eleven digits get their check digit added; twelve are checked. With a Font, the first and last digits are drawn outside the symbol, and their bars reach down with the guard bars.
public static Barcode UpcA(string digits, EanUpcOptions? options = null)
Parameters
digitsstring11 or 12 digits.
optionsEanUpcOptions
Returns
- Barcode
The barcode, with the 12 digits (and the add-on after a space) as its human-readable text.
Examples
// A book: the ISBN as EAN-13, its check digit added, and the price as an EAN-5 add-on.
Barcode book = Barcode.Ean13("978020137962", new EanUpcOptions { AddOn = "52495" });
// Fitted into a rectangle, with the digits between the guard bars.
using Raster<Rgba8> label = Raster.Create(400, 200, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = label.CreateCanvas())
{
canvas.DrawBarcode(book, new RectF(10, 10, 380, 180), Rgba8.Black, new BarcodeDrawOptions { Font = font });
}
// A UPC-A number written in its short UPC-E form.
Barcode small = Barcode.UpcE("042100005264");
Exceptions
- ArgumentException
The text is not 11 or 12 digits, or the check digit is wrong.
UpcE(string, EanUpcOptions?)
Makes a UPC-E barcode (ISO/IEC 15420), the zero-suppressed form of UPC-A. It takes the six UPC-E digits (number system 0), the number system (0 or 1) and the six digits, those and the check digit, or a UPC-A number of 11 or 12 digits, which is compressed to UPC-E.
public static Barcode UpcE(string digits, EanUpcOptions? options = null)
Parameters
digitsstring6, 7 or 8 UPC-E digits, or 11 or 12 UPC-A digits.
optionsEanUpcOptions
Returns
- Barcode
The barcode, with the number system, six digits and check digit (and the add-on after a space) as its human-readable text.
Examples
// A book: the ISBN as EAN-13, its check digit added, and the price as an EAN-5 add-on.
Barcode book = Barcode.Ean13("978020137962", new EanUpcOptions { AddOn = "52495" });
// Fitted into a rectangle, with the digits between the guard bars.
using Raster<Rgba8> label = Raster.Create(400, 200, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = label.CreateCanvas())
{
canvas.DrawBarcode(book, new RectF(10, 10, 380, 180), Rgba8.Black, new BarcodeDrawOptions { Font = font });
}
// A UPC-A number written in its short UPC-E form.
Barcode small = Barcode.UpcE("042100005264");
Exceptions
- ArgumentException
The text is not 6, 7, 8, 11 or 12 digits, the number system is not 0 or 1, the check digit is wrong, or a UPC-A number has too few zeros to compress.