SkillAgentSearch skills...

BarcodeGenerator

Barcode generator based on SkiaSharp library

Install / Use

/learn @TyKonKet/BarcodeGenerator

README

📊 BarcodeGenerator

NuGet NuGet Downloads Build Status codecov Benchmarks License: MIT

A compact, SkiaSharp-based .NET library for generating common 1D barcodes. Focused on reliability, correctness and a small API surface so it's easy to use from services and agent workflows.

Example:

using var barcode = new Barcode(opt => opt.Type = BarcodeTypes.Ean13);
string validated = barcode.Encode("123456789012");
barcode.Export("barcode.png");

📖 Documentation

👉 Complete Documentation - Comprehensive guides, API reference, and examples

Quick Links


🚀 Supported Barcode Types

10 industry-standard formats for every use case:

| Type | Use Case | Example | |------|----------|---------| | EAN-13 | 🛒 Retail products, European standard | 1234567890128 | | UPC-A | 🇺🇸 North American retail, grocery | 012345678905 | | UPC-E | 📦 Compact retail, small packages | 01234565 | | ISBN-13 | 📚 Books and publications | 9781234567897 | | EAN-8 | 📦 Small packages, compact spaces | 12345670 | | CODE-39 | 🏭 Industrial, automotive, defense | ABC-123 | | CODE-93 | 📋 Logistics, inventory management | ABC123 | | CODE-128 | 📊 High-density alphanumeric encoding | ABC123xyz | | CODABAR | 🏥 Libraries, blood banks, logistics | A123456A | | ITF | 📦 Distribution, warehousing, cartons | 12345678 |


Key points

  • Compact, easy-to-use API (fluent configuration)
  • Built-in validation helpers (see BarcodeValidator)
  • Export templating: use placeholders like {barcode}, {format} in file names
  • Cross-platform rendering using SkiaSharp

📦 Installation

Choose your preferred installation method:

Package Manager Console:

Install-Package TyKonKet.BarcodeGenerator

CLI Command:

dotnet add package TyKonKet.BarcodeGenerator

🎯 Quick Start

Get up and running in 30 seconds:

1️⃣ Install

dotnet add package TyKonKet.BarcodeGenerator

2️⃣ Generate

using SkiaSharp;
using TyKonKet.BarcodeGenerator;

// Simple barcode generation
using var barcode = new Barcode(options => {
    options.Type = BarcodeTypes.Ean13;
    options.Height = 50;
    options.Scaling = 3;
});

string validatedCode = barcode.Encode("123456789012");
barcode.Export("my-barcode.png");

3️⃣ Customize

// Advanced styling with custom colors and fonts
using var styledBarcode = new Barcode(options => {
    options.Type = BarcodeTypes.Ean13;
    options.ForegroundColor = SKColors.DarkBlue;
    options.TextColor = SKColors.Red;           // 🆕 Independent text color!
    options.BackgroundColor = SKColors.LightGray;
    options.UseTypeface("Arial", SKFontStyle.Bold);
    options.Margins = 10;
});

string result = styledBarcode.Encode("123456789012");
styledBarcode.Export("styled-barcode.png", SKEncodedImageFormat.Png, 100);

🔥 Pro Tip: Export Templating

// Dynamic file naming with placeholders
barcode.Export("output/{barcode}_{quality}.{format}", SKEncodedImageFormat.Png, 95);
// Creates: output/1234567890128_95.png

Validate Before Encoding

// NEW: Validate barcode data without encoding
var result = BarcodeValidator.Validate("123456789012", BarcodeTypes.Ean13);
if (result.IsValid)
{
    Console.WriteLine($"✓ Valid: {result.ValidatedBarcode}");
    // Output: ✓ Valid: 1234567890128 (with check digit)
}
else
{
    Console.WriteLine($"✗ Errors: {string.Join(", ", result.Errors)}");
    // Get suggestions for compatible barcode types (opt-in)
    var resultWithSuggestions = BarcodeValidator.Validate("ABC123", BarcodeTypes.Ean13, includeSuggestions: true);
    if (resultWithSuggestions.SuggestedTypes.Count > 0)
    {
        Console.WriteLine($"💡 Try: {string.Join(", ", resultWithSuggestions.SuggestedTypes)}");
    }
}

💡 Need more help? Check out our Getting Started Guide for step-by-step tutorials and examples.
📚 Validation API: See the complete Validation API Documentation for detailed usage.


Common use cases

  • E-commerce product barcodes (EAN/UPC)
  • Inventory and asset tracking
  • Library ISBN generation
  • Label printing and batch export

📋 Configuration Options

The BarcodeOptions class provides extensive customization capabilities:

| Option | Description | Default | |--------|-------------|---------| | Type | Barcode encoding type (EAN-13, UPC-A, ISBN-13, EAN-8, CODE-93, CODE-128) | EAN-8 | | Height | Height of barcode bars | 30 pixels | | Scaling | Scale factor for the entire image | 5x | | Margins | Spacing around the barcode | 2 pixels | | Colors | Background, foreground, and text colors (independent control) | White/Black | | Text Rendering | Show/hide text below barcode | Enabled | | Font Options | Custom fonts, styles, and loading methods | System default |

📚 Detailed Configuration: See our BarcodeOptions API Reference for complete documentation.


🔧 Framework Compatibility

BarcodeGenerator supports multiple .NET framework versions for maximum compatibility:

| Framework | Version | Target Scenario | |-----------|---------|-----------------| | .NET Standard 2.0 | 2.0+ | Core compatibility for most scenarios | | .NET Framework | 4.6.2+ | Legacy Windows applications | | .NET 8.0 | 8.0+ | Long-term support version | | .NET 10.0 | 10.0+ | Latest stable version |


🔄 Breaking Changes

Version 2.1.0

  • PolySharp Integration: The library now includes the PolySharp package to enhance compatibility. If you encounter any issues, please report them by opening an issue on our GitHub repository. For more details, visit the PolySharp GitHub repository.
  • API Rename: EncodesExtensions has been renamed to BarcodeTypeExtensions to better reflect its purpose. Update consuming code accordingly.
  • Framework requirement: .NET 6 support has been dropped in favor of the current net8.0/net10.0 targets; make sure callers move to those runtimes.

Version 2.0.0

  • Framework Requirement: No longer supports .NET Standard 1.3 (requires .NET Standard 2.0+).
  • API Changes: Redesigned for improved usability and customization.
  • SkiaSharp Update: Updated to SkiaSharp 3.116.1 for better performance.

📖 Migration Guide: See our Getting Started documentation for updated API usage patterns.


🗺️ Roadmap

✅ Recently completed

  • CODE-39, CODE-128, CODABAR, ITF and UPC-E
  • Validation API: standalone validation without encoding (BarcodeValidator)
  • PolySharp integration to improve compatibility across target frameworks
  • Independent text color support (BarcodeOptions.TextColor) and rendering improvements

Have an idea? Start a discussion or vote on features!


🤝 Contributing

We welcome contributions from the community! 🎉

👉 Full Contributing Guide - Complete guide to contributing with setup, workflows, and guidelines

Quick Start:

Essential Checks:

  • Run tests: dotnet test --configuration Release
  • Check coverage: ./tools/run-coverage.sh
  • Follow our Code of Conduct

Every contribution matters - from typo fixes to new features!


📄 License

This library is released under the MIT License. See the LICENSE file for details.


📚 Explore Full Documentation | 🚀 Getting Started Guide | 🔧 API Reference

View on GitHub
GitHub Stars5
CategoryDevelopment
Updated4mo ago
Forks2

Languages

C#

Security Score

87/100

Audited on Nov 23, 2025

No findings