Skip to footer content
USING IRONBARCODE

Barcode Generator C# Source Code Using IronBarcode

How Do I Install a Barcode Generator Library Using NuGet Package Manager?

Open Visual Studio and install the NuGet package with this command in the Package Manager Console:

Install-Package BarCode

Barcode Generator C# Source Code Using IronBarcode: Image 1 - Installation

The NuGet package supports .NET 8, .NET 6, .NET Core, .NET Standard, and .NET Framework—making it compatible with Windows applications and cross-platform .NET applications. IronBarcode supports deployment to Docker containers, Azure, and Linux servers. Find more details and reference documentation on the Iron Software GitHub project.

How Can I Generate a Simple Barcode Image File Using C#?

Create barcode images with just a few lines of code. The following example shows barcode generation that saves a PNG image file:

using IronBarCode;
// Generate a simple barcode and encode the string data
var barcode = BarcodeWriter.CreateBarcode("SKU-78432-X", BarcodeWriterEncoding.Code128);
// Save the barcode as a PNG image file
barcode.SaveAsPng("product-barcode.png");
using IronBarCode;
// Generate a simple barcode and encode the string data
var barcode = BarcodeWriter.CreateBarcode("SKU-78432-X", BarcodeWriterEncoding.Code128);
// Save the barcode as a PNG image file
barcode.SaveAsPng("product-barcode.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The BarcodeWriter.CreateBarcode() method accepts a string to encode and the barcode format from BarcodeWriterEncoding. The returned GeneratedBarcode reference provides styling methods and export options to save to PNG, JPEG, BMP, TIFF, PDF, or HTML.

Output

Barcode Generator C# Source Code Using IronBarcode: Image 2 - Barcode Output

Code128 is relevant for logistics and inventory systems—it can encode uppercase letters, lowercase letters, numbers, and special characters. This barcode type ensures proper scanning at shipping facilities and retail environments.

How Do I Create a QR Code and Other Barcode Types?

IronBarcode supports all major barcode formats, including 2D barcode types such as QR Code and Data Matrix. Generate a QR code with similar syntax:

using IronBarCode;
// Create a QR code and encode URL data
var qrCode = BarcodeWriter.CreateBarcode(
    "https://ironsoftware.com",
    BarcodeWriterEncoding.QRCode
);
qrCode.SaveAsPng("website-qr.png");
using IronBarCode;
// Create a QR code and encode URL data
var qrCode = BarcodeWriter.CreateBarcode(
    "https://ironsoftware.com",
    BarcodeWriterEncoding.QRCode
);
qrCode.SaveAsPng("website-qr.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

QR code barcode types excel at storing URLs and larger data payloads. The library handles error correction automatically, ensuring the barcode remains scannable even when partially damaged.

Output

Barcode Generator C# Source Code Using IronBarcode: Image 3 - QR Code Output

For retail products requiring EAN-13 barcodes, generate barcode images like this:

using IronBarCode;
// Generate an EAN-13 barcode compatible with UPC for retail print applications
var eanBarcode = BarcodeWriter.CreateBarcode("5901234123457", BarcodeWriterEncoding.EAN13);
eanBarcode.SaveAsPng("retail-product.png");
using IronBarCode;
// Generate an EAN-13 barcode compatible with UPC for retail print applications
var eanBarcode = BarcodeWriter.CreateBarcode("5901234123457", BarcodeWriterEncoding.EAN13);
eanBarcode.SaveAsPng("retail-product.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

EAN-13 provides details relevant for point-of-sale systems worldwide. The library calculates check digits automatically based on personal experience from .NET developers building retail applications.

Output

Barcode Generator C# Source Code Using IronBarcode: Image 4 - EAN-13 Barcode Output

How Can I Create a Styled QR Code with Advanced Styling Options?

Professional barcode generation often requires advanced styling options to adjust colors and add annotations. The GeneratedBarcode class provides a fluent API with styling methods:

using IronBarCode;
using IronSoftware.Drawing;
// Create a styled QR code with advanced styling options
var styledBarcode = BarcodeWriter
    .CreateBarcode("INV-2025-001847", BarcodeWriterEncoding.Code128)
    .ResizeTo(400, 120)
    .SetMargins(20)
    .ChangeBarCodeColor(Color.DarkBlue)
    .AddAnnotationTextAboveBarcode("Invoice Number:")
    .AddBarcodeValueTextBelowBarcode();
// Verify to ensure proper scanning after styling
bool isReadable = styledBarcode.Verify();
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
styledBarcode.SaveAsPng("styled-invoice-barcode.png");
using IronBarCode;
using IronSoftware.Drawing;
// Create a styled QR code with advanced styling options
var styledBarcode = BarcodeWriter
    .CreateBarcode("INV-2025-001847", BarcodeWriterEncoding.Code128)
    .ResizeTo(400, 120)
    .SetMargins(20)
    .ChangeBarCodeColor(Color.DarkBlue)
    .AddAnnotationTextAboveBarcode("Invoice Number:")
    .AddBarcodeValueTextBelowBarcode();
// Verify to ensure proper scanning after styling
bool isReadable = styledBarcode.Verify();
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
styledBarcode.SaveAsPng("styled-invoice-barcode.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The fluent API lets you chain styling methods to adjust colors, set margins, and add text in one statement. The Verify() method indicates whether your barcode remains machine-readable—ensuring proper scanning in production after applying non-standard colors or resizing to small dimensions.

To generate multiple barcodes with consistent styling, explore the customized barcode style guide, which provides details on bitmap manipulation and font customization.

How Do I Export Barcodes to Different Image Formats?

Generate barcode images in multiple formats for different use cases. The library saves to PNG, JPEG, BMP, TIFF, PDF, and HTML:

using IronBarCode;
var barcode = BarcodeWriter.CreateBarcode("EXPORT-TEST", BarcodeWriterEncoding.Code128);
// Export barcode images to various formats
barcode.SaveAsPng("barcode.png");           // Web compatible image
barcode.SaveAsJpeg("barcode.jpg");          // Compressed JPEG format
barcode.SaveAsTiff("barcode.tiff");         // High-quality TIFF for print
barcode.SaveAsPdf("barcode.pdf");           // PDF document format
barcode.SaveAsHtmlFile("barcode.html");     // HTML for web embedding
// Get as bitmap stream for web APIs or database storage
System.IO.Stream barcodeStream = barcode.ToStream();
System.Drawing.Bitmap bitmapImage = barcode.ToBitmap();
using IronBarCode;
var barcode = BarcodeWriter.CreateBarcode("EXPORT-TEST", BarcodeWriterEncoding.Code128);
// Export barcode images to various formats
barcode.SaveAsPng("barcode.png");           // Web compatible image
barcode.SaveAsJpeg("barcode.jpg");          // Compressed JPEG format
barcode.SaveAsTiff("barcode.tiff");         // High-quality TIFF for print
barcode.SaveAsPdf("barcode.pdf");           // PDF document format
barcode.SaveAsHtmlFile("barcode.html");     // HTML for web embedding
// Get as bitmap stream for web APIs or database storage
System.IO.Stream barcodeStream = barcode.ToStream();
System.Drawing.Bitmap bitmapImage = barcode.ToBitmap();
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The ToStream() method returns barcode data compatible with ASP.NET Core web APIs and Blazor applications. The ToBitmap() method provides a System.Drawing.Bitmap reference for further image manipulation. For stamping barcodes onto existing PDF documents, see the PDF barcode stamping guide.

Output

Barcode Generator C# Source Code Using IronBarcode: Image 5 - PNG Barcode Output

Barcode Generator C# Source Code Using IronBarcode: Image 6 - HTML Barcode Output

What Cross-Platform .NET Environments Are Supported?

IronBarcode supports barcode generation across all .NET platforms. Deploy to:

  • Windows applications: Desktop apps, Windows Services, IIS web servers
  • Linux: Docker containers, AWS Lambda, Azure Functions
  • macOS: Development and server environments
  • Mobile: .NET MAUI and Xamarin
  • .NET Core and .NET Standard: Cross-platform compatible library

The Docker setup guide provides details on the required dependencies for containerized deployments. Other answers to deployment questions are available in the troubleshooting documentation.

Best Practices for Barcode Generation

When generating barcode images in C# .NET applications, it’s essential to follow best practices to ensure proper scanning, readability, and compatibility. Here are some guidelines to keep in mind:

  • Choose the right barcode format: Select a barcode format that matches your use case, whether it’s a QR code for storing URLs and data, Code 128 for inventory tracking, or EAN-13 for retail products. IronBarcode supports a wide range of barcode formats, so you can generate the type that best fits your .NET applications.
  • Ensure proper scanning: Always include sufficient margins (quiet zones) around your barcode images. This white space is crucial for barcode scanners to accurately detect and decode the barcode, especially when printing or displaying on different devices.
  • Leverage advanced styling options: Take advantage of IronBarcode’s advanced styling options to adjust font, color, and size. Customizing your barcode images can improve readability and help them blend seamlessly into your application’s design, while still ensuring they remain compatible with scanning devices.
  • Generate multiple barcodes efficiently: If your application needs to generate multiple barcodes, use batch processing or loops to automate the process. This approach not only saves time but also ensures consistency across all generated barcode images.
  • Test and verify barcode images: Before deploying your solution, always test your barcode images across various scanners and environments. IronBarcode provides built-in verification methods to confirm that your barcodes are readable and compliant with industry standards.

By following these best practices, you can generate high-quality barcode images compatible with a wide range of systems and devices, ensuring proper scanning and reliable performance in your .NET applications.

Conclusion

This C# barcode generator tutorial demonstrates how to generate barcode images using IronBarcode. The code examples covered creating simple barcode types, styled QR code generation, and exporting to PNG, JPEG, TIFF, BMP, and PDF formats—all compatible with .NET Core, .NET Standard, and Windows applications.

Download IronBarcode to add barcode functionality to your .NET applications. Explore licensing options starting at $799, or start a free 30-day trial to generate barcode images in your environment.

Frequently Asked Questions

How do I install IronBarcode using NuGet Package Manager?

To install IronBarcode via NuGet Package Manager, open your Visual Studio, navigate to 'Tools' -> 'NuGet Package Manager' -> 'Manage NuGet Packages for Solution', search for 'IronBarcode', and click 'Install'.

What types of barcodes can I generate using IronBarcode?

IronBarcode supports generating a wide range of barcode types including QR codes, Code 39, Code 128, UPC, EAN, and many more.

Can IronBarcode generate barcodes in different image formats?

Yes, IronBarcode can generate barcodes in various image formats such as PNG, JPEG, GIF, BMP, and TIFF.

Is IronBarcode compatible with .NET Core?

Yes, IronBarcode is fully compatible with .NET Core, allowing you to integrate barcode generation into cross-platform applications.

How can I customize the appearance of a barcode using IronBarcode?

IronBarcode provides customization options like setting the barcode's color, background color, label, size, and more to tailor the appearance to your needs.

Does IronBarcode support barcode reading and scanning?

Yes, IronBarcode not only generates barcodes but also supports reading and scanning barcodes from images and documents.

What are the system requirements for using IronBarcode?

IronBarcode requires a .NET environment. It is compatible with .NET Framework 4.0 and above, and .NET Core 2.0 and above.

Can I generate barcodes in bulk using IronBarcode?

Yes, IronBarcode allows you to generate barcodes in bulk by iterating through your data and creating barcodes programmatically.

Is there a trial version of IronBarcode available?

Yes, IronBarcode offers a free trial version that you can use to evaluate its features before purchasing a license.

What kind of support is available for IronBarcode users?

IronBarcode offers comprehensive support including documentation, tutorials, and a dedicated support team to assist with any issues you may encounter.

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he ...
Read More