IRONSOFTWAREHOME

How to Generate Barcode Images in C# .NET Applications

Jacob Mellor, Chief Technology Officer @ Team Iron
Jacob Mellor
Updated: August 2, 2026

Need to quickly generate professional barcode images in your .NET applications? This tutorial shows you exactly how to create, customize, and export barcodes using IronBarcode - from simple one-line implementations to advanced styling techniques that give you complete control over your barcode appearance.

Quickstart: Create and Save a Barcode Image Instantly

With IronBarcode you can generate and export a barcode image in just one simple call. Use the CreateBarcode method with your text, choose the format and size, then call SaveAsPng - no complex setup needed.

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2Copy and run this code snippet.

    IronBarCode.BarcodeWriter.CreateBarcode("Hello123", BarcodeWriterEncoding.Code128, 200, 100).SaveAsPng("barcode.png");
    C#
  3. 3Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer

How Do I Install a Barcode Generator Library in C#?

Installing IronBarcode takes just seconds using the NuGet Package Manager. You can install it directly through the Package Manager Console or download the DLL manually.

PM > Install-Package BarCode

IronBarcode simplifies barcode generation in .NET applications with powerful features and easy-to-use APIsIronBarcode provides comprehensive barcode generation capabilities for .NET developers

How Can I Generate a Simple Barcode Using C#?

Creating your first barcode requires just two lines of code. The example below demonstrates generating a standard Code128 barcode and saving it as an image file.

using IronBarCode;
using IronSoftware.Drawing;

// Fluent API for Barcode Image generation.
string value = "https://ironsoftware.com/csharp/barcode";
AnyBitmap barcodeBitmap = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.PDF417).ResizeTo(300, 200).SetMargins(100).ToBitmap();
System.Drawing.Bitmap barcodeLegacyBitmap = (System.Drawing.Bitmap)barcodeBitmap;

The BarcodeWriter.CreateBarcode() method is your entry point for barcode generation. It accepts two parameters: the data you want to encode and the barcode format from the BarcodeWriterEncoding enum. IronBarcode supports all major barcode formats including Code128, Code39, EAN13, UPCA, PDF417, DataMatrix, and QRCode codes.

Once generated, the GeneratedBarcode object provides multiple export options. You can save it as various image formats (PNG, JPEG, GIF, TIFF), export to PDF, or even retrieve it as a System.Drawing.Bitmap for further processing in your application.

Example of a Code128 barcode generated using IronBarcode in C#A Code128 barcode generated with IronBarcode displaying a URL

Can I Customize the Appearance of Generated Barcodes?

IronBarcode offers extensive customization options that go far beyond basic barcode generation. You can add annotations, adjust colors, set margins, and control every aspect of your barcode's appearance.

using IronBarCode;
using IronSoftware.Drawing;

// Create a QR code with advanced styling options
GeneratedBarcode myBarCode = BarcodeWriter.CreateBarcode(
    "https://ironsoftware.com/csharp/barcode", 
    BarcodeWriterEncoding.QRCode
);

// Add descriptive text above the barcode
myBarCode.AddAnnotationTextAboveBarcode("Product URL:");

// Display the encoded value below the barcode
myBarCode.AddBarcodeValueTextBelowBarcode();

// Set consistent margins around the barcode
myBarCode.SetMargins(100);

// Customize the barcode color (purple in this example)
myBarCode.ChangeBarCodeColor(Color.Purple);

// Export as an HTML file for web integration
myBarCode.SaveAsHtmlFile("MyBarCode.html");

The GeneratedBarcode class provides a rich set of methods for customization:

  • Annotations: Use AddAnnotationTextAboveBarcode() and AddAnnotationTextBelowBarcode() to add custom labels or instructions around your barcode
  • Value Display: The AddBarcodeValueTextBelowBarcode() method automatically displays the encoded data in human-readable format
  • Spacing: Control whitespace with SetMargins() to ensure proper scanning and visual appeal
  • Colors: Change foreground and background colors using ChangeBarCodeColor() and ChangeBackgroundColor()
  • Export Options: Save as image files, PDFs, or self-contained HTML documents
Customized purple QR code with annotations generated using IronBarcode styling featuresA styled QR code featuring custom color and annotation text

For detailed customization options, explore the GeneratedBarcode class documentation which covers all available styling methods and properties.

How Do I Create and Export a Barcode in One Line of Code?

IronBarcode implements a fluent API design pattern that enables method chaining for more concise and readable code. This approach is particularly useful when applying multiple transformations to your barcode.

using IronBarCode;
using IronSoftware.Drawing;

// Generate, style, and convert a barcode in a single statement
string value = "https://ironsoftware.com/csharp/barcode";

// Create PDF417 barcode with chained operations
AnyBitmap barcodeBitmap = BarcodeWriter
    .CreateBarcode(value, BarcodeWriterEncoding.PDF417)  // Create PDF417 barcode
    .ResizeTo(300, 200)                                  // Set specific dimensions
    .SetMargins(10)                                      // Add 10px margins
    .ToBitmap();                                         // Convert to bitmap

// Convert to System.Drawing.Bitmap for legacy compatibility
System.Drawing.Bitmap legacyBitmap = barcodeBitmap;

The fluent API pattern offers several advantages:

  • Readability: Chain operations in a logical sequence that reads like natural language
  • Efficiency: Reduce variable declarations and intermediate steps
  • Flexibility: Easily add or remove operations without restructuring your code

Common fluent operations include:

  • ResizeTo(): Control exact barcode dimensions
  • SetMargins(): Add consistent spacing
  • ChangeBarCodeColor(): Modify appearance
  • AddAnnotationTextAboveBarcode(): Include descriptive text
  • ToBitmap(), SaveAsPng(), SaveAsPdf(): Export in various formats
PDF417 barcode created using IronBarcode's fluent API with custom dimensionsA PDF417 barcode generated using fluent method chaining

What Barcode Formats Are Supported by IronBarcode?

IronBarcode supports comprehensive barcode format generation through the BarcodeWriterEncoding enum. Supported formats include:

1D Barcodes: Code128, Code39, Code93, Codabar, ITF, MSI, Plessey, UPCA, UPCE, EAN8, EAN13
2D Barcodes: QRCode, DataMatrix, PDF417, Aztec, MaxiCode
Specialized Formats: IntelligentMail, DataBar, DataBarExpanded, and various GS1 standards

Each format has specific characteristics and use cases. For example, QRCode codes excel at storing URLs and large amounts of data, while EAN13 is standard for retail products. Learn more about choosing the right barcode format for your application.

How Can I Verify My Generated Barcode Is Readable?

Quality assurance is critical for barcode implementation. IronBarcode includes built-in verification to ensure your generated barcodes remain scannable:

// Generate and verify a barcode
GeneratedBarcode myBarcode = BarcodeWriter
    .CreateBarcode("TEST123", BarcodeWriterEncoding.Code128)
    .ResizeTo(200, 100)
    .ChangeBarCodeColor(Color.DarkBlue);

// Verify the barcode is still readable after modifications
bool isReadable = myBarcode.Verify("TEST123");
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
C#

The Verify(expectedValue) method checks whether your barcode remains machine-readable after applying transformations like resizing or recoloring. This is especially important when using non-standard colors or very small sizes.

Where Can I Find More Barcode Generation Examples?

To expand your barcode generation capabilities, explore these additional resources:

Source Code and Examples

Download the complete source code for this tutorial:

Advanced Topics

API Documentation

Ready to Generate Professional Barcodes in Your Application?

IronBarcode makes barcode generation straightforward while providing the flexibility needed for professional applications. Whether you need simple product codes or complex 2D barcodes with custom styling, IronBarcode handles it all with minimal code.

Download IronBarcode today and start generating barcodes in minutes. Need help choosing the right license? Check our licensing options or request a free trial key to test IronBarcode in your production environment.

Frequently Asked Questions

How do I generate a barcode image in C# using IronBarcode?

To generate a barcode image using IronBarcode, you can use the `CreateBarcode` method by specifying your data and desired barcode format. Afterward, use `SaveAsPng` to export the barcode image.

What barcode formats are supported by IronBarcode?

IronBarcode supports a wide range of barcode formats including 1D formats like `Code128`, `EAN13`, and 2D formats such as `QRCode` and `PDF417`. Specialized formats are also available, like `IntelligentMail` and `GS1` standards.

Can I customize the appearance of my barcode with IronBarcode?

Yes, IronBarcode allows extensive customization including annotations, color adjustments, and setting margins. You can use methods like `ChangeBarCodeColor()` and `AddAnnotationTextAboveBarcode()` for customization.

How can I verify if my generated barcode is readable?

IronBarcode provides a verification feature using the `Verify(expectedValue)` method, which helps to check if your barcode is still machine-readable after transformations like resizing or recoloring.

Is it possible to create and export a barcode in C# with just one line of code?

Yes, IronBarcode's fluent API allows you to generate and export a barcode in one line using method chaining. For example, you can use `CreateBarcode().ResizeTo().SaveAsPng()` to execute multiple operations concisely.

How do I install IronBarcode in a .NET project?

IronBarcode can be installed through the NuGet Package Manager in Visual Studio or by manually downloading the DLL. This allows you to quickly integrate barcode generation capabilities in your project.

What is the fluent API in IronBarcode and its benefits?

The fluent API in IronBarcode enables method chaining, making your code more concise and readable by allowing multiple operations in a single statement—ideal for applying transformations to barcodes efficiently.

Where can I find more barcode generation examples using IronBarcode?

You can find additional resources and examples in the IronBarcode GitHub repository, or by exploring the advanced topics sections on the official Iron Software website, where detailed guides and tutorials are available.

Can IronBarcode export barcodes to formats other than images?

Yes, IronBarcode can export barcodes to various formats including PDF and HTML, offering flexibility for integration into different types of applications and workflows.

What features does IronBarcode offer for professional applications?

IronBarcode provides professional features such as complete styling customization, comprehensive format support, built-in verification, and efficient batch processing options to meet business-level requirements.

Jacob Mellor, Chief Technology Officer @ Team Iron
Chief Technology Officer

Jacob Mellor is Chief Technology Officer at Iron Software and a visionary engineer pioneering C# PDF technology. As the original developer behind Iron Software's core codebase, he has shaped the company's product architecture since its inception, transforming it alongside CEO Cameron Rimington into a 50+ person company serving NASA, Tesla, and global government agencies.

...
Read More

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required