Skip to content

Repository files navigation

DRIT.Barcode

A pure-managed .NET barcode generation and recognition library supporting 60+ symbologies across 1D, 2D, and postal categories — with all encoding and decoding algorithms implemented from scratch, no third-party barcode libraries, and rendering powered by DRIT.Drawing for both raster and true vector output.

DRIT.Barcode is built around a symbology engine registry: every barcode type is an ISymbologyEngine that turns codetext into a bar pattern or module matrix, and a single BarcodeRenderer draws that result onto any DRIT.Drawing Graphics surface — raster Bitmap, SVG, or EMF — unchanged.

.NET License: MIT Tests


Table of Contents


What is DRIT.Barcode?

DRIT.Barcode is a pure-managed .NET barcode generation and recognition library. It does not depend on any third-party barcode library. The entire stack — every symbology encoder, the recognition pipeline (luminance, binarizer, 1D/2D readers), Reed-Solomon error correction, GS1 Application Identifier parsing, and the rendering layer — is implemented in source.

Key positioning:

  • 60+ symbologies. 1D linear (Code 39/93/128, EAN/UPC, Codabar, ITF, 2-of-5 family), GS1 DataBar (7 variants), 2D matrix (QR, DataMatrix, PDF417 family, Aztec, MaxiCode, Han Xin, DotCode), postal (Australia Post, POSTNET, PLANET, OneCode, RM4SCC, and more), and complex barcodes (Swiss QR Bill, HIBC, Mailmark).
  • Generation and recognition. BarcodeGenerator produces barcode images; BarCodeReader decodes barcodes from images with quality presets, multi-region search, and inverted-image support.
  • True vector output. Because rendering goes through DRIT.Drawing, any barcode can be emitted as SVG or EMF — not an embedded raster — as well as PNG, JPEG, BMP, GIF, TIFF, and PDF.
  • GS1-first. GS1 Application Identifier parsing and formatting, GS1-128, GS1 DataMatrix, GS1 QR, and GS1 Composite Bar — with human-readable parentheses notation on both generation and recognition.
  • Familiar API. The public surface (BarcodeGenerator, BarCodeReader, EncodeTypes, DecodeType, QualitySettings) follows the established .NET barcode library conventions, so it is easy to pick up.
  • Zero external barcode dependencies. No NuGet barcode packages, no native libraries. Rendering uses DRIT.Drawing; PDF output uses DRIT.Pdf.

Features

  • Generation of 60+ barcode symbologies via BarcodeGenerator with full visual customization.
  • Recognition of 1D and 2D barcodes via BarCodeReader with quality presets, region targeting, and inverted-image detection.
  • 1D symbologies: Code 11, Code 39 Standard/Extended, Code 93 Standard/Extended, Code 128, GS1-128, Codabar, Code 16K, Codablock-F, Patch Code, Interleaved 2 of 5, Standard/IATA/Matrix/Italian Post/COOP 2 of 5, EAN-13, EAN-8, UPC-A, UPC-E, EAN-14, ISBN, ISSN, Bookland EAN, Supplement (2/5-digit add-on), Deutsche Post Identcode/Leitcode.
  • GS1 DataBar: Omnidirectional, Truncated, Stacked, Stacked Omnidirectional, Limited, Expanded, Expanded Stacked.
  • 2D symbologies: QR, GS1 QR, PDF417, Micro PDF417, Macro PDF417, Compact PDF417, DataMatrix, GS1 DataMatrix, Aztec, Aztec Rune, MaxiCode, Han Xin, DotCode, GS1 Composite Bar, UPC-A GS1 Coupon.
  • Postal symbologies: Australia Post, POSTNET, PLANET, OneCode (USPS Intelligent Mail), RM4SCC, Singapore Post, Dutch KIX, Mailmark.
  • Complex barcodes: Swiss QR Bill, HIBC LIC/PAS (Code 128 and Code 39), Mailmark codetext, MaxiCode codetext.
  • GS1 support: Application Identifier parsing and formatting, parentheses/bracket notation, FNC1 handling — on both generation and recognition.
  • Visual customization: bar/background colors, code text font and placement, captions above/below, borders with dash styles, padding, rotation, resolution, X-dimension, bar height, bar width reduction, auto-sizing.
  • Output formats: PNG, JPEG, BMP, GIF, TIFF, TIFF (CMYK), SVG (vector), EMF (vector), PDF.
  • Recognition features: quality presets (HighPerformance → MaxBarCodes), multi-region search, inverted-image recognition, checksum validation, GS1 text formatting, HIBC text formatting.
  • Error correction: in-house Reed-Solomon and Galois field arithmetic for 2D symbologies.
  • Zero external barcode dependencies. No NuGet barcode packages, no native libraries.

Supported Symbologies

Category Symbologies
1D Linear Code 11, Code 39 Std/Ext, Code 93 Std/Ext, Code 128, GS1-128, Codabar, Code 16K, Codablock-F, Patch Code, Interleaved 2 of 5, Standard/IATA/Matrix/Italian Post/COOP 2 of 5, EAN-13, EAN-8, UPC-A, UPC-E, EAN-14, ISBN, ISSN, Bookland EAN, Supplement, Deutsche Post Identcode/Leitcode
GS1 DataBar Omnidirectional, Truncated, Stacked, Stacked Omnidirectional, Limited, Expanded, Expanded Stacked
2D QR, GS1 QR, PDF417, Micro PDF417, Macro PDF417, Compact PDF417, DataMatrix, GS1 DataMatrix, Aztec, Aztec Rune, MaxiCode, Han Xin, DotCode, GS1 Composite Bar, UPC-A GS1 Coupon
Postal Australia Post, POSTNET, PLANET, OneCode, RM4SCC, Singapore Post, Dutch KIX, Mailmark
Complex Swiss QR Bill, HIBC LIC (Code 128/39), HIBC PAS (Code 128/39), Mailmark, MaxiCode codetext

Recognition is supported for the common 1D symbologies (Code 39/93/128, GS1-128, Codabar, EAN-13/8, UPC-A/E, Interleaved 2 of 5, HIBC) and 2D symbologies (QR, GS1 QR, DataMatrix, GS1 DataMatrix, PDF417, Aztec).

Output Formats

Format Type Description
PNG Raster Lossless, alpha — default
JPEG Raster Lossy
BMP Raster Uncompressed
GIF Raster 256-color, LZW
TIFF Raster Lossless
TIFF (CMYK) Raster CMYK color space for print
SVG Vector True vector — scalable, no embedded raster
EMF Vector Enhanced Metafile — true vector
PDF Document Via DRIT.Pdf

Platform Independence

DRIT.Barcode is implemented in pure managed C# and targets net8.0, so it runs on:

  • .NET 8.0+
  • Windows, Linux, and macOS

It has no external barcode dependencies — no NuGet barcode packages and no native libraries. Rendering uses DRIT.Drawing (raster + vector codecs); PDF output uses DRIT.Pdf.


Get Started

Generate a Barcode

using DRIT.Barcode;
using DRIT.Barcode.Generation;

using var gen = new BarcodeGenerator(EncodeTypes.Code128, "DRIT.Barcode");
gen.Parameters.Barcode.XDimension.Pixels = 2f;
gen.Parameters.Barcode.BarHeight.Pixels = 80f;
gen.Parameters.BackColor = Color.White;
gen.Parameters.BarColor = Color.Black;

gen.Save("barcode.png", BarCodeImageFormat.Png);

Recognize Barcodes

using DRIT.Barcode;
using DRIT.Barcode.Recognition;

using var reader = new BarCodeReader("barcode.png", DecodeType.Code128);
BarCodeResult[] results = reader.ReadBarCodes();

foreach (BarCodeResult result in results)
{
    Console.WriteLine("Type:   {0}", result.CodeTypeName);
    Console.WriteLine("Text:   {0}", result.CodeText);
    Console.WriteLine("Region: {0}", result.Region);
}

Generate to Vector SVG and EMF

Any barcode can be emitted as true vector output — the bars are drawn as vector rectangles, not embedded rasters.

using var gen = new BarcodeGenerator(EncodeTypes.QR, "https://github.com/dritsoftware/DRIT.Barcode");
gen.Parameters.Barcode.XDimension.Pixels = 4f;

gen.Save("qr.svg", BarCodeImageFormat.Svg);   // true vector SVG
gen.Save("qr.emf", BarCodeImageFormat.Emf);   // true vector EMF

GS1 Barcodes

GS1 codetext can be written in human-readable parentheses notation; the parser converts it to FNC1-separated raw codetext for the engine. On recognition, decoded GS1 data is formatted back to parentheses notation.

using DRIT.Barcode;
using DRIT.Barcode.Generation;

// GS1-128 with Application Identifiers
using var gen = new BarcodeGenerator(
    EncodeTypes.GS1Code128, "(01)12345678901231(10)LOT123(17)251231");
gen.Save("gs1-128.png", BarCodeImageFormat.Png);

// GS1 DataMatrix
using var dm = new BarcodeGenerator(
    EncodeTypes.GS1DataMatrix, "(01)04212345678905(11)250101");
dm.Save("gs1-dm.png", BarCodeImageFormat.Png);

// GS1 QR
using var qr = new BarcodeGenerator(
    EncodeTypes.GS1QR, "(01)12345678901231(21)SERIAL123");
qr.Save("gs1-qr.png", BarCodeImageFormat.Png);

Swiss QR Bill

using DRIT.Barcode;
using DRIT.Barcode.Complex;

var bill = new SwissQRBill
{
    CreditorIBAN = "CH4431999123000889012",
    CreditorName = "Robert Schneider",
    CreditorAddress = "Rue du Lac 1268",
    CreditorPostalCode = "2501",
    CreditorCity = "Biel",
    CreditorCountry = "CH",
    Amount = 199.95m,
    Currency = "CHF",
    ReferenceType = "QRR",
    Reference = "210000000003139471430009017",
    UnstructuredMessage = "Invoice 2025-001",
};

using var gen = new ComplexBarcodeGenerator(bill);
gen.Save("swiss-qr.png", BarCodeImageFormat.Png);

Visual Customization

using var gen = new BarcodeGenerator(EncodeTypes.EAN13, "5901234123457");

// Colors
gen.Parameters.BackColor = Color.White;
gen.Parameters.BarColor = Color.Black;

// Code text
gen.Parameters.CodeTextParameters.Visible = true;
gen.Parameters.CodeTextParameters.Location = CodeLocation.Below;
gen.Parameters.CodeTextParameters.Font.FamilyName = "Arial";
gen.Parameters.CodeTextParameters.Font.Size.Point = 8f;

// Captions
gen.Parameters.CaptionAbove.Text = "DRIT.Barcode";
gen.Parameters.CaptionAbove.Visible = true;
gen.Parameters.CaptionBelow.Text = "EAN-13";
gen.Parameters.CaptionBelow.Visible = true;

// Border and padding
gen.Parameters.Border.Visible = true;
gen.Parameters.Border.Width.Pixels = 2f;
gen.Parameters.Border.DashStyle = BorderDashStyle.Solid;
gen.Parameters.Padding.Left.Pixels = 10f;
gen.Parameters.Padding.Right.Pixels = 10f;

// Resolution and rotation
gen.Parameters.Resolution = 300f;
gen.Parameters.RotationAngle = 0f;

gen.Save("ean13.png", BarCodeImageFormat.Png);

Recognition Quality Presets

using var reader = new BarCodeReader("photo.jpg", DecodeType.AllSupportedTypes);

// Maximize accuracy at the cost of speed
reader.QualitySettings = QualitySettings.MaxQuality;

BarCodeResult[] results = reader.ReadBarCodes();
Console.WriteLine("Found {0} barcode(s).", results.Length);

Presets: HighPerformance, NormalQuality (default), HighQuality, MaxQuality, MaxBarCodes.


Architecture

DRIT.Barcode/
├── Generation/        BarcodeGenerator, EncodeTypes, BarcodeParameters, parameters
├── Recognition/       BarCodeReader, DecodeType, QualitySettings, results
│   └── Internal/      Luminance, binarizer, binary bitmap, readers
│       ├── OneD/      Code 39/93/128, Codabar, EAN/UPC, ITF readers
│       ├── QR/        QR detector, decoder, bit-matrix parser
│       ├── DataMatrix/ DataMatrix detector, decoder, version
│       ├── Aztec/     Aztec detector, decoder
│       └── PDF417/    PDF417 detector, scanning decoder, error correction
├── Symbologies/       Symbology engines (encoding)
│   ├── OneD/          Code 39/93/128, EAN, UPC, Codabar, ITF, 2-of-5, Patch Code
│   ├── TwoD/          QR, DataMatrix, PDF417, Aztec, MaxiCode, Han Xin, DotCode
│   ├── Postal/        Australia Post, POSTNET/PLANET, OneCode, RM4SCC, ...
│   ├── DataBar/       GS1 DataBar variants + general field encoder
│   └── HIBC/          HIBC LIC/PAS engines
├── Complex/           SwissQRBill, Mailmark, MaxiCode codetext
├── GS1/               GS1 Application Identifier parser and formatter
├── HIBC/              HIBC encoder
├── Rendering/         BarcodeRenderer, layout, EMF/PDF/TIFF-CMYK writers
├── Common/            BitArray, BitMatrix, Reed-Solomon, Galois field
└── Enums/             Image formats, auto-size, QR error level, ...

The Symbology Engine

Each barcode type is an ISymbologyEngine registered in SymbologyEngineRegistry. The generation path is a single pipeline:

   Codetext ──► ISymbologyEngine.Encode() ──► SymbologyResult ──► BarcodeLayout ──► BarcodeRenderer
                  (bar pattern or              (pattern +          (bars + text +     (DRIT.Drawing
                   module matrix)               modules + text)     border + padding)   Graphics surface)
                                                                                              │
                                                                                              ├──► Bitmap (PNG/JPEG/BMP/GIF/TIFF)
                                                                                              ├──► SvgImage (SVG)
                                                                                              └──► Metafile (EMF)
  • SymbologyResult carries either a 1D bar pattern (bool[]), a 2D module matrix (bool[,]), or stacked row patterns — the engine output is format-agnostic.
  • BarcodeLayout is the computed geometry: bar rectangles, code text, captions, border, and padding, all in pixel space.
  • BarcodeRenderer draws a BarcodeLayout onto any DRIT.Drawing Graphics surface. The same render call produces raster, SVG, or EMF output depending on the surface — one renderer, three outputs.

The Recognition Pipeline

Recognition inverts the generation path through a dedicated decode pipeline:

   Image ──► BitmapLuminanceSource ──► Binarizer ──► BinaryBitmap ──► Reader ──► BarCodeResult
              (grayscale)              (1-bit)         (bit matrix)    (1D/2D)     (text + bytes + region)
  • BitmapLuminanceSource converts a DRIT.Drawing Bitmap to a grayscale luminance array.
  • GlobalHistogramBinarizer thresholds the luminance to a 1-bit BinaryBitmap using a global histogram.
  • ReadersMultiFormatOneDReader for 1D (with row scanning), QRCodeReader, DataMatrixReader, PDF417Reader, AztecReader for 2D — detect, decode, and verify checksums / error correction.
  • QualitySettings controls the speed/accuracy trade-off: inverted-image scanning, additional 1D scans, median smoothing, salt-and-pepper filtering, and white-spot removal.
  • GS1 / HIBC formatting — decoded text with FNC1/GS separators or + prefixes is converted back to human-readable notation before returning.

Building

dotnet build DRIT.Barcode.slnx -c Release
dotnet test DRIT.Barcode.slnx -c Release

Requires .NET 8.0 SDK. The library targets net8.0 and consumes the published DRIT.Drawing (rendering + codecs) and DRIT.Pdf (PDF output) packages. The public solution is self-contained and does not require sibling DR-IT repositories.

Credits

DRIT.Barcode's encoding and decoding algorithms were developed using freely available knowledge sources — Wikipedia articles, public specifications (GS1, USPS, Swiss QR Bill), and the following open-source projects, whose source code served as a reference and was ported to C#. Full copyright notices and license texts are in THIRD-PARTY-NOTICES.md.

Project License Used For
ZXing Apache 2.0 1D/2D encoding and recognition algorithms (Code 39/93/128, EAN/UPC, Codabar, ITF, QR, DataMatrix, PDF417, Aztec, MaxiCode)
Zint BSD-3-Clause Symbologies not in ZXing (Code 11, Code 16K, Codablock-F, Patch Code, 2-of-5 variants, DataBar, GS1 Composite, Han Xin, DotCode, postal barcodes, HIBC, Mailmark)
libdmtx BSD-2-Clause DataMatrix encoding reference
QRCoder MIT QR encoding reference
BarcodeLib Apache 2.0 Code 39 / Code 128 encoding reference

License

DRIT.Barcode is licensed under the MIT License.

About

Pure-managed .NET barcode generation and recognition library for QR, DataMatrix, Aztec, PDF417, GS1, and more.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages