VOOZH about

URL: https://ironsoftware.com/csharp/barcode/tutorials/csharp-barcode-image-generator/

⇱ How to Generate Barcode Images in C# .NET 10 Applications | IronBarcode


Skip to footer content

On This Page

  1. IronBarcode
  2. Tutorials
  3. Generating Barcode Images in C# .NET

How to Generate Barcode Images in C# .NET Applications

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. Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode
  2. Copy and run this code snippet.

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

    Start using IronBarcode in your project today with a free trial

Minimal Workflow (5 steps)

  1. Install IronBarcode via NuGet Package Manager
  2. Generate a Simple Barcode with One Line of Code
  3. Apply Custom Styling and Annotations to Your Barcode
  4. Export Barcodes as Images, PDFs, or HTML
  5. Use Fluent API for Efficient Barcode Generation

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.

Install-Package BarCode
πŸ‘ IronBarcode simplifies barcode generation in .NET applications with powerful features and easy-to-use APIs
IronBarcode 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.

:path=/static-assets/barcode/content-code-examples/tutorials/csharp-barcode-image-generator-3.cs
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;
Imports IronBarCode
Imports IronSoftware.Drawing

' Fluent API for Barcode Image generation.
Private value As String = "https://ironsoftware.com/csharp/barcode"
Private barcodeBitmap As AnyBitmap = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.PDF417).ResizeTo(300, 200).SetMargins(100).ToBitmap()
Private barcodeLegacyBitmap As System.Drawing.Bitmap = CType(barcodeBitmap, System.Drawing.Bitmap)
$vbLabelText   $csharpLabel

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.

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.

:path=/static-assets/barcode/content-code-examples/tutorials/csharp-barcode-image-generator-4.cs
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");
Imports IronBarCode
Imports IronSoftware.Drawing

' Create a QR code with advanced styling options
Dim myBarCode As GeneratedBarcode = 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")
$vbLabelText   $csharpLabel

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

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.

:path=/static-assets/barcode/content-code-examples/tutorials/csharp-barcode-image-generator-5.cs
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;
Imports IronBarCode
Imports IronSoftware.Drawing

' Generate, style, and convert a barcode in a single statement
Dim value As String = "https://ironsoftware.com/csharp/barcode"

' Create PDF417 barcode with chained operations
Dim barcodeBitmap As AnyBitmap = 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
Dim legacyBitmap As System.Drawing.Bitmap = barcodeBitmap
$vbLabelText   $csharpLabel

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

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:

:path=/static-assets/barcode/content-code-examples/tutorials/csharp-barcode-image-generator-6.cs
// 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();
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
Imports System.Drawing

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

' Verify the barcode is still readable after modifications
Dim isReadable As Boolean = myBarcode.Verify()
Console.WriteLine($"Barcode verification: {(If(isReadable, "PASS", "FAIL"))}")
$vbLabelText   $csharpLabel

The Verify() 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 can I create a barcode image in C#?

To create a barcode image in C#, you can use IronBarcode's BarcodeWriter.CreateBarcode() method. This allows you to specify the data and barcode format, and then save the image with formats like PNG or JPEG using methods such as SaveAsPng().

What are the steps to install IronBarcode in a .NET project?

You can install IronBarcode in your .NET project by using NuGet Package Manager in Visual Studio. Alternatively, you can download the DLL from the IronBarcode website and add it to your project references.

How can I export a barcode as a PDF in C#?

IronBarcode allows exporting barcodes as PDFs using the SaveAsPdf() method from the GeneratedBarcode class, offering a straightforward way to save your barcodes in PDF format.

What customization options are available for barcodes in C#?

IronBarcode provides extensive customization options, such as changing barcode colors with ChangeBarCodeColor(), adding text annotations using AddAnnotationTextAboveBarcode(), and setting margins with SetMargins().

How can I quickly create and style a barcode in one line of code?

Using IronBarcode's Fluent API, you can create and style a barcode in one line with method chaining: BarcodeWriter.CreateBarcode(data, encoding).ResizeTo(300, 200).SetMargins(10).SaveAsPng(path).

How do I ensure that my barcode is scannable after modifications?

To verify the scannability of a barcode after styling or resizing, use the Verify() method on the GeneratedBarcode object to check its machine-readability.

Can I generate QR codes with logos in C#?

Yes, IronBarcode supports QR code generation with embedded logos using the QRCodeWriter class, which includes features for logo insertion and enhanced error correction levels.

What is the process for generating multiple barcodes efficiently in C#?

You can efficiently generate multiple barcodes in C# using IronBarcode, which supports batch processing and allows for the use of loops or parallel processing to handle high-volume barcode generation.

What file formats can I use to export barcodes in C#?

IronBarcode supports exporting barcodes in various formats, including PNG, JPEG, GIF, TIFF, BMP, PDF, and HTML, providing flexibility for different application needs.

How can I add human-readable text below a barcode in C#?

To add human-readable text below a barcode in C#, use the AddBarcodeValueTextBelowBarcode() method, which automatically displays the encoded value in a text format beneath the barcode image.

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, ...

Read More
Ready to Get Started?
Nuget Downloads 2,287,186 | Version: 2026.6 just released

Still Scrolling?

Want proof fast? PM > Install-Package BarCode
run a sample watch your string become a barcode.

Get your FREE

30-day Trial Key instantly.

15-day Trial Key instantly.

The trial form was submitted
successfully.

Your trial key should be in the email.
If it is not, please contact
support@ironsoftware.com

πŸ‘ bullet_checked
No credit card or account creation required
πŸ‘ bullet_test
Test in production
without watermarks
πŸ‘ bullet_calendar
30 days fully
functional product
πŸ‘ bullet_support
24/5 technical
support during trial
Install with NuGet
Version: 2026.6
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
Download DLL
Version: 2026.6
Download Now
Manually install into your project
  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 $749

Have a question? Get in touch with our development team.

Now you've installed with Nuget
Your browser is now downloading IronBarcode

Next step: Start free 30-day Trial

No credit card required

  • Test in a live environment
  • Fully-functional product
  • 24/5 technical support

Thank You

Your trial key should be in the email.
If it is not, please contact
support@ironsoftware.com
Get your free 30-day Trial Key instantly.
Thank you.
If you'd like to speak to our licensing team:
πŸ‘ badge_greencheck_in_yellowcircle
The trial form was submitted
successfully.

Your trial key should be in the email.
If it is not, please contact
support@ironsoftware.com

Have a question? Get in touch with our development team.
No credit card or account creation required
Now you've installed with Nuget
Your browser is now downloading IronBarcode

Next step: Start free 30-day Trial

No credit card required

  • Test in a live environment
  • Fully-functional product
  • 24/5 technical support
Thank you.
View your license options:
Thank you.
If you'd like to speak to our licensing team:
Have a question? Get in touch with our development team.
Have a question? Get in touch with our development team.
Talk to Sales Team

Book a No-obligation Consult

How we can help:
  • Consult on your workflow & pain points
  • See how other companies solve their .NET document needs
  • All your questions answered to make sure you have all the information you need. (No commitment whatsoever.)
  • Get a tailored quote for your project's needs
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
Book Free Live Demo

Book a 30-minute, personal demo.

No contract, no card details, no commitments.

Here's what to expect:
  • A live demo of our product and its key features
  • Get project specific feature recommendations
  • All your questions are answered to make sure you have all the information you need.
    (No commitment whatsoever.)
CHOOSE TIME
YOUR INFO
Book your free Live Demo

Trusted by Millions of Engineers Worldwide

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me