/AnyBarcode

A cross-platform barcode generation library for CSharp

Primary LanguageC#GNU General Public License v2.0GPL-2.0

AnyBarcode

nuget nuget Build status

A cross-platform barcode image generation library for CSharp. AnyBarcode is built on .Net and supports Windows and most Unix environments.

AnyBarcode was originally based on BarcodeLib library by Brad Barnhill.

Supported Symbology List
Code 128 Code 93 Code 39 (Extended / Full ASCII)
Code11 EAN-8 FIM (Facing Identification Mark)
UPC-A UPC-E Pharmacode
MSI PostNet Standard 2 of 5
ISBN Codabar Interleaved 2 of 5
ITF-14 Telepen UPC Supplemental 2
JAN-13 EAN-13 UPC Supplemental 5

Usage

var barcode = new Barcode();
var barcodeImage = barcode.Encode<Rgba32>("0123456789", BarcodeType.Upca, 290, 120);

This library is cross-platform (Windows & Unix) and has no dependency on Windows GDI. If you need to convert the barcode image to a Windows Bitmap, you can use the following:

var barcode = new Barcode();
var barcodeImage = barcode.Encode<Rgba32>("0123456789", BarcodeType.Upca);

using var memoryStream = new MemoryStream();
var imageConfiguration = barcodeImage.GetConfiguration();
var imageEncoder = imageConfiguration.ImageFormatsManager.FindEncoder(PngFormat.Instance);
barcodeImage.Save(memoryStream, imageEncoder);
memoryStream.Seek(0, SeekOrigin.Begin);

// create a Bitmap
var bitmap = new Bitmap(memoryStream);
bitmap.SetResolution((float)barcodeImage.Metadata.HorizontalResolution, (float)barcodeImage.Metadata.VerticalResolution);

Examples

Generate a UPCA barcode with a label overlay:

var barcode = new Barcode();
var barcodeImage = barcode.Encode<Rgba32>("0123456789", BarcodeType.Upca, 290, 120, true);

UPCA Barcode

Generate a Code128 barcode with no overlay:

var barcode = new Barcode();
var barcodeImage = barcode.Encode<Rgba32>("0123456789", BarcodeType.Code128, 290, 60);

Code128 Barcode