COMPARE TO OTHER COMPONENTS

A Comparison between IronBarcode and ZXing.NET

Published December 12, 2022
Share:

A barcode scanner may not always be appropriate for our applications. You may already have a digital image of the barcode, and want to know what it represents in English text. Furthermore, this scanner only reads 1-D barcodes, which contain a limited amount of data and can only be used in Windows RT Class library. 2-D barcodes (also known as QR codes) are now common and can hold a lot more information.

A C# based application can be created to read barcodes using simple API calls and a few coding steps. A .NET supported application runs on Windows, macOS, or Linux without relying on any third-party tool or API.

This article will compare the two most powerful .NET Core app libraries for reading barcodes programmatically. These two libraries are IronBarcode and ZXing.NET. We will see what makes the IronBarcode more powerful and robust than ZXing.NET.


What is ZXing.NET

ZXing.NET is a library that decodes and generates barcodes (like QR Code, PDF 417, EAN, UPC, Aztec, Data Matrix, Codabar). ZXing, which stands for "zebra crossing," is a Java-based, open-source library that supports a variety of 1D and 2D barcode formats.

Its essential characteristics are as follows:

  • It has the ability to store URLs, contact details, calendar events, and more
  • It is tailored to Java SE applications
  • It allows for barcode scanner integration via intent
  • It is a straightforward Google Glass app

What is IronBarcode

IronBarcode is a C# library that allows programmers to read and generate barcodes. As a leading barcode library, IronBarcode supports a wide variety of 1-dimensional and 2-dimensional barcodes, including decorated (colored and branded) QR codes. It supports .NET Standard and Core Versions 2 and higher, allowing it to be used cross-platform on Azure, Linux, macOS, Windows and Web. IronBarcode is a well-known class library or component for the .NET system that allows C#, VB.NET, and F# developers to work with standardized programming languages. It will enable customers to browse scanner tags and create new standardized labels. It works exceptionally well with 2D barcodes and other 3D standardized barcodes.

IronBarcode now supports 2D barcodes. It provides functionality for optimizing the coloring, styling, and pixelation of these codes and the ability to add logos to them for use in print or advertising material. This library also can read skewed and deformed barcodes, something which other barcode software may not be able to read.

Installing IronBarcode and ZXing.NET

Installation of ZXing.NET

To use the ZXing.NET library, install the following two packages in your ASP.NET Core application using the NuGet Package Manager Console:

1. ZXing.Net

Install-Package ZXing.Net

2. ZXing.Net.Bindings.CoreCompat.System.Drawing

Install-Package ZXing.Net.Bindings.CoreCompat.System.Drawing -Version 0.16.5-beta

Alternatively, install ZXing.NET in your project using the NuGet Package Manager. To do so, go to Tools > NuGet Package Manager > Manage NuGet packages for solutions..., then switch to the "Browse" tab and search for "ZXing.NET".

A Comparison between IronBarcode and Zxing.NET, Figure 1: ASP.NET Web Application

ASP.NET Web Application

Installation of IronBarcode

Install IronBarcode using the NuGet Package Manager or by downloading the DLL directly from the product website. The IronBarcode namespace contains all the IronBarcode classes.

IronBarcode can be installed using the NuGet Package Manager for Visual Studio: the package name is "Barcode".

Install-Package BarCode

Creating 2D Barcode

Using ZXing.NET

First, make a new folder called 'qrr' inside the root folder of the project file.

We will then proceed to create QR files and store the image system files inside the 'qrr' folder.

Inside the Controller, add the GenerateFile() method as shown below in the source code.

public ActionResult GenerateFile()
{
    return View();
}

[HttpPost]
public ActionResult GenerateFile(string qrText)
{
    Byte [] byteArray;
    var width = 250; // width of the QR Code
    var height = 250; // height of the QR Code
    var margin = 0;
    var qrCodeWriter = new ZXing.BarcodeWriterPixelData
    {
        Format = ZXing.BarcodeFormat.QR_CODE,
        Options = new QrCodeEncodingOptions
        {
            Height = height,
            Width = width,
            Margin = margin
        }
    };
    var pixelData = qrCodeWriter.Write(qrText);

    // creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
    using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
    {
        using (var ms = new MemoryStream())
        {
            var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            try
            {
                // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan, pixelData.Pixels.Length);
            }
            finally
            {
                bitmap.UnlockBits(bitmapData);
            }

            // save to folder
            string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
            bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);

            // save to stream as PNG
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byteArray = ms.ToArray();
        }
    }
    return View(byteArray);
}
public ActionResult GenerateFile()
{
    return View();
}

[HttpPost]
public ActionResult GenerateFile(string qrText)
{
    Byte [] byteArray;
    var width = 250; // width of the QR Code
    var height = 250; // height of the QR Code
    var margin = 0;
    var qrCodeWriter = new ZXing.BarcodeWriterPixelData
    {
        Format = ZXing.BarcodeFormat.QR_CODE,
        Options = new QrCodeEncodingOptions
        {
            Height = height,
            Width = width,
            Margin = margin
        }
    };
    var pixelData = qrCodeWriter.Write(qrText);

    // creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
    using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
    {
        using (var ms = new MemoryStream())
        {
            var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            try
            {
                // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan, pixelData.Pixels.Length);
            }
            finally
            {
                bitmap.UnlockBits(bitmapData);
            }

            // save to folder
            string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
            bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);

            // save to stream as PNG
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byteArray = ms.ToArray();
        }
    }
    return View(byteArray);
}
Public Function GenerateFile() As ActionResult
	Return View()
End Function

<HttpPost>
Public Function GenerateFile(ByVal qrText As String) As ActionResult
	Dim byteArray() As Byte
	Dim width = 250 ' width of the QR Code
	Dim height = 250 ' height of the QR Code
	Dim margin = 0
	Dim qrCodeWriter = New ZXing.BarcodeWriterPixelData With {
		.Format = ZXing.BarcodeFormat.QR_CODE,
		.Options = New QrCodeEncodingOptions With {
			.Height = height,
			.Width = width,
			.Margin = margin
		}
	}
	Dim pixelData = qrCodeWriter.Write(qrText)

	' creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
	Using bitmap = New System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
		Using ms = New MemoryStream()
			Dim bitmapData = bitmap.LockBits(New System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
			Try
				' we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
				System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan, pixelData.Pixels.Length)
			Finally
				bitmap.UnlockBits(bitmapData)
			End Try

			' save to folder
			Dim fileGuid As String = Guid.NewGuid().ToString().Substring(0, 4)
			bitmap.Save(Server.MapPath("~/qrr") & "/file-" & fileGuid & ".png", System.Drawing.Imaging.ImageFormat.Png)

			' save to stream as PNG
			bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
			byteArray = ms.ToArray()
		End Using
	End Using
	Return View(byteArray)
End Function
VB   C#

The only change left is to save the QR code file inside the 'qrr' folder. This is performed using the two lines of code below.

string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);
string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);
Dim fileGuid As String = Guid.NewGuid().ToString().Substring(0, 4)
bitmap.Save(Server.MapPath("~/qrr") & "/file-" & fileGuid & ".png", System.Drawing.Imaging.ImageFormat.Png)
VB   C#

You must also create the GenerateFile view and include the following code in it. The GenerateFile view is identical to the Index view.

@model Byte []
@using (Html.BeginForm(null, null, FormMethod.Post))
{
    <table>
        <tbody>
            <tr>
                <td>
                    <label>Enter text for creating QR Code</label>
                </td>
                <td>
// text box to enter text...
                    <input type="text" name="qrText" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button>Submit</button>
                </td>
            </tr>
        </tbody>
    </table>
}
@{
    if (Model != null)
    {
        <h3>QR Code Successfully Generated</h3>
// img tag to display generated QR code...
        <img src="@String.Format("data:image/png;base64,{0}", Convert.ToBase64String(Model))" />
    }
}
@model Byte []
@using (Html.BeginForm(null, null, FormMethod.Post))
{
    <table>
        <tbody>
            <tr>
                <td>
                    <label>Enter text for creating QR Code</label>
                </td>
                <td>
// text box to enter text...
                    <input type="text" name="qrText" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button>Submit</button>
                </td>
            </tr>
        </tbody>
    </table>
}
@{
    if (Model != null)
    {
        <h3>QR Code Successfully Generated</h3>
// img tag to display generated QR code...
        <img src="@String.Format("data:image/png;base64,{0}", Convert.ToBase64String(Model))" />
    }
}
model Function [using](Html.BeginForm ByVal As (Nothing, Nothing, FormMethod.Post)) As Byte()
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: <table> <tbody> <tr> <td> <label> Enter text for creating QR Code</label> </td> <td> <input type="text" name="qrText" /> </td> </tr> <tr> <td colspan="2"> <button> Submit</button> </td> </tr> </tbody> </table>
	"qrText" /> </td> </tr> (Of tr) <td colspan="2"> (Of button) Submit</button> </td> </tr> </tbody> </table>
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: <table> <tbody> <tr> <td> <label> Enter text for creating QR Code</label> </td> <td> <input type="text" name="qrText" /> </td> </tr> <tr> <td colspan
	"text" name="qrText" /> </td> </tr> (Of tr) <td colspan
	(Of table) (Of tbody) (Of tr) (Of td) (Of label) Enter text for creating QR Code</label> </td> (Of td) <input type="text" name
End Function
@
If True Then
	If Model IsNot Nothing Then
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
		(Of h3) QR Code Successfully Generated</h3> <img src="@String.Format("data:image/png
		base64,
		If True Then
			0
		End If
		", Convert.ToBase64String(Model))" />
	End If
End If
VB   C#

Enter any value in the text box and click the 'Submit' button. The QR Code will be generated and saved as a .PNG file in the 'qrr' folder.

A Comparison between IronBarcode and ZXing.NET, Figure 2: QR Code Generator

QR Code Generator

A Comparison between IronBarcode and ZXing.NET, Figure 3: QR Code Files Displayed

QR Code Files Displayed

Supported Barcode Formats

IronBarcode supports a wide range of commonly used barcode formats, including:

  • QR codes with logos and colors(including decorated and branded codes)
  • Multi-format barcodes including Aztec, Data Matrix, CODE 93, CODE 128, RSS Expanded Databar, UPS MaxiCode, and USPS, IMB (OneCode) barcodes
  • RSS-14 and PDF-417 stacked linear barcodes
  • UPCA, UPCE, EAN-8, EAN-13, Codabar, ITF, MSI, and Plessey are traditional numerical barcode formats.

Create and Save Barcode

var MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");
Image  MyBarCodeImage = MyBarCode.Image;
Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
string DataURL = MyBarCode.ToDataUrl();
string ImgTagForHTML = MyBarCode.ToHtmlTag();
byte [] PngBytes = MyBarCode.ToPngBinaryData();
     // Binary barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream()){
    // Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
}
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50);
var MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");
Image  MyBarCodeImage = MyBarCode.Image;
Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
string DataURL = MyBarCode.ToDataUrl();
string ImgTagForHTML = MyBarCode.ToHtmlTag();
byte [] PngBytes = MyBarCode.ToPngBinaryData();
     // Binary barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream()){
    // Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
}
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50);
Dim MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128)
MyBarCode.SaveAsImage("MyBarCode.png")
MyBarCode.SaveAsGif("MyBarCode.gif")
MyBarCode.SaveAsHtmlFile("MyBarCode.html")
MyBarCode.SaveAsJpeg("MyBarCode.jpg")
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.SaveAsPng("MyBarCode.png")
MyBarCode.SaveAsTiff("MyBarCode.tiff")
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")
Dim MyBarCodeImage As Image = MyBarCode.Image
Dim MyBarCodeBitmap As Bitmap = MyBarCode.ToBitmap()
Dim DataURL As String = MyBarCode.ToDataUrl()
Dim ImgTagForHTML As String = MyBarCode.ToHtmlTag()
Dim PngBytes() As Byte = MyBarCode.ToPngBinaryData()
	 ' Binary barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
Using PdfStream As System.IO.Stream = MyBarCode.ToPdfStream()
	' Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
End Using
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50)
VB   C#

On the other hand, ZXing is a Java-based open-source 1D/2D barcode image processing library. UPC-A, UPC-E, EAN-8, Code 93, Code 128, QR Code, Data Matrix, Aztec, PDF 417, and other barcode formats are supported.

A Comparison between IronBarcode and Zxing.NET, Figure 4: Supported Barcode Formats

Supported Barcode Formats

Create QR Code files using IronBarcode

To create QR codes with IronBarcode, we can use the QRCodeWriter class rather than the BarcodeWriter class. This class introduces some novel and intriguing features to create QR codes. It enables us to set the QR error correction level, allowing you to strike a balance between the size and readability of your QR code.

// Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png");
// Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png");
' Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png")
VB   C#

Error correction allows us to specify how easy it will be to read a QR code in real-world situations. Higher levels of error correction result in larger QR codes with more pixels and complexity. In the below image, we see the QR code file displayed.

A Comparison between IronBarcode and ZXing.NET, Figure 5: Supported Barcode Formats

QR Code Image

We begin by specifying the barcode's value and the barcode format from the IronBarcode.BarcodeWriterEncoding enum. We can then save as an image, a System.Drawing.Image, or a Bitmap code object. That's all the source code you need!

// Generate a simple BarCode image and save as PNG using following namespaces
using IronBarCode;
GeneratedBarcode MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
MyBarCode.SaveAsPng("MyBarCode.png");
// This line opens the image in your default image viewer
System.Diagnostics.Process.Start("MyBarCode.png");
// Generate a simple BarCode image and save as PNG using following namespaces
using IronBarCode;
GeneratedBarcode MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
MyBarCode.SaveAsPng("MyBarCode.png");
// This line opens the image in your default image viewer
System.Diagnostics.Process.Start("MyBarCode.png");
' Generate a simple BarCode image and save as PNG using following namespaces
Imports IronBarCode
Private MyBarCode As GeneratedBarcode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128)
MyBarCode.SaveAsPng("MyBarCode.png")
' This line opens the image in your default image viewer
System.Diagnostics.Process.Start("MyBarCode.png")
VB   C#
A Comparison between IronBarcode and ZXing.NET, Figure 6: Create a Barcode Image in C# Example

Create a Barcode Image in C# Example

IronBarcode also supports stylizing QR codes, such as having a logo graphic placed and snapped to a grid in the exact center of the image. It can also be colored to match a specific brand or graphic identity.

For testing, create a logo in the following code sample below and see how simple it is to use the QRCodeWriter.CreateQRCodeWithLogo method.

// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
' Adding a Logo
Dim MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500)
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen)
VB   C#
A Comparison between IronBarcode and ZXing.NET, Figure 7: Create QR Code With Logo Image

Create QR Code With Logo Image

Finally, we save the generated QR code as a PDF file. For your convenience, the final line of code saves QR code as HTML file.

// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
//Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf");
//Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html");
// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
//Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf");
//Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html");
' Adding a Logo
Dim MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500)
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen)
'Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf")
'Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html")
VB   C#

Below, we see how to create, style, and export a barcode with just one line of code.

IronBarcode includes a fluent API that is similar to System.Linq. We create a barcode, set its margins, and export it to bitmap in a single line by chaining method calls. This can be very useful and makes the code easier to read.

using IronBarCode;
using System.Drawing;
 // Fluent API for Barcode image generation.
string MyValue = "https://ironsoftware.com/csharp/barcode";
Bitmap BarcodeBmp = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417).ResizeTo(300,200).SetMargins(100).ToBitmap();
using IronBarCode;
using System.Drawing;
 // Fluent API for Barcode image generation.
string MyValue = "https://ironsoftware.com/csharp/barcode";
Bitmap BarcodeBmp = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417).ResizeTo(300,200).SetMargins(100).ToBitmap();
Imports IronBarCode
Imports System.Drawing
 ' Fluent API for Barcode image generation.
Private MyValue As String = "https://ironsoftware.com/csharp/barcode"
Private BarcodeBmp As Bitmap = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417).ResizeTo(300,200).SetMargins(100).ToBitmap()
VB   C#

As a result, a System.Drawing.Image of a PDF417 barcode appears as shown below:

A Comparison between IronBarcode and ZXing.NET, Figure 8: Simple, fluent PDF417 Barcode Generation in C#

Simple, fluent PDF417 Barcode Generation in C#

Reading QR Code Files

Reading QR Codes with IronBarcode

Reading a barcode or QR code is a breeze when you use the IronBarcode class library in conjunction with the .NET barcode reader. In our first example, we can see how to read a barcode using only one line of code.

A Comparison between IronBarcode and ZXing.NET, Figure 9: Code128 Barcode Image to be Scanned with C#

Code128 Barcode Image to be Scanned with C#

We can get barcode's value, image, encoding type, and binary data (if any) and then output it to the console.

using IronBarCode;
using System;
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png");
if (Result !=null && Result.Text == "https://ironsoftware.com/csharp/barcode/")
{
  Console.WriteLine("GetStarted was a success.  Read Value: " + Result.Text);
}
using IronBarCode;
using System;
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png");
if (Result !=null && Result.Text == "https://ironsoftware.com/csharp/barcode/")
{
  Console.WriteLine("GetStarted was a success.  Read Value: " + Result.Text);
}
Imports IronBarCode
Imports System
Private Result As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png")
If Result IsNot Nothing AndAlso Result.Text = "https://ironsoftware.com/csharp/barcode/" Then
  Console.WriteLine("GetStarted was a success.  Read Value: " & Result.Text)
End If
VB   C#

Reading Barcodes Inside PDFs

We'll look at reading a scanned PDF document and finding all the one-dimensional barcodes in a few lines of code.

As you can see, it's very similar to reading a single barcode from a single document, except we now know what page number the barcode was discovered on.

using IronBarCode;
using System;
using System.Drawing;
// Multiple barcodes may be scanned up from a single document or image.  A PDF document may also be used as the input image
PagedBarcodeResult [] PDFResults = BarcodeReader.ReadBarcodesFromPdf("MultipleBarcodes.pdf");
// Work with the results
foreach (var PageResult in PDFResults)
{
    string Value = PageResult.Value;
    int PageNum = PageResult.PageNumber;
    System.Drawing.Bitmap Img = PageResult.BarcodeImage;
    BarcodeEncoding BarcodeType = PageResult.BarcodeType;
    byte [] Binary = PageResult.BinaryValue;
    Console.WriteLine(PageResult.Value+" on page "+ PageNum);
}
using IronBarCode;
using System;
using System.Drawing;
// Multiple barcodes may be scanned up from a single document or image.  A PDF document may also be used as the input image
PagedBarcodeResult [] PDFResults = BarcodeReader.ReadBarcodesFromPdf("MultipleBarcodes.pdf");
// Work with the results
foreach (var PageResult in PDFResults)
{
    string Value = PageResult.Value;
    int PageNum = PageResult.PageNumber;
    System.Drawing.Bitmap Img = PageResult.BarcodeImage;
    BarcodeEncoding BarcodeType = PageResult.BarcodeType;
    byte [] Binary = PageResult.BinaryValue;
    Console.WriteLine(PageResult.Value+" on page "+ PageNum);
}
Imports IronBarCode
Imports System
Imports System.Drawing
' Multiple barcodes may be scanned up from a single document or image.  A PDF document may also be used as the input image
Private PDFResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdf("MultipleBarcodes.pdf")
' Work with the results
For Each PageResult In PDFResults
	Dim Value As String = PageResult.Value
	Dim PageNum As Integer = PageResult.PageNumber
	Dim Img As System.Drawing.Bitmap = PageResult.BarcodeImage
	Dim BarcodeType As BarcodeEncoding = PageResult.BarcodeType
	Dim Binary() As Byte = PageResult.BinaryValue
	Console.WriteLine(PageResult.Value &" on page " & PageNum)
Next PageResult
VB   C#

You will get a result data with all bitmap barcodes in the PDF.

A Comparison between IronBarcode and ZXing.NET, Figure 10: Reading Barcodes Stored Inside PDF Results

Reading Barcodes Stored Inside PDF Results

Reading Barcodes from GIF and TIFF

// Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
PagedBarcodeResult [] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels);
foreach (var PageResult in MultiFrameResults)
{
//...
}
// Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
PagedBarcodeResult [] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels);
foreach (var PageResult in MultiFrameResults)
{
//...
}
' Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
Dim MultiFrameResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels)
For Each PageResult In MultiFrameResults
'...
Next PageResult
VB   C#
A Comparison between IronBarcode and ZXing.NET, Figure 11: Reading Barcodes from a Multi-frame TIFF Image

Reading Barcodes from a Multi-frame TIFF Image

The following example shows how to read QR codes and PDF-417 barcodes from a scanned PDF. We have set an appropriate level of barcode rotation correction and barcode image correction to lightly clean the document without incurring a significant performance penalty by over-egging our needs.

// PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
var ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels);
// Work with the results
foreach (var PageResult in ScanResults)
{
  string Value = PageResult.Value;
  ///...
}
// PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
var ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels);
// Work with the results
foreach (var PageResult in ScanResults)
{
  string Value = PageResult.Value;
  ///...
}
' PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
Dim ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels)
' Work with the results
For Each PageResult In ScanResults
  Dim Value As String = PageResult.Value
  '''...
Next PageResult
VB   C#
A Comparison between IronBarcode and ZXing.NET, Figure 12: Reading Barcodes from a Scanned PDF Document

Reading Barcodes from a Scanned PDF Document

Reading CORRUPTED QR Codes from Bitmap Images

The example below shows that this C# barcode library can even read a corrupted barcode thumbnail.

Correction of barcode thumbnail size is done automatically. IronBarcode in C# makes a file readable.

The reader methods automatically detect barcode images that are too small to be a legitimate barcode and upscale them. They clean all the digital noise associated with working with thumbnails, making them readable again.

// Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128);
// Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128);
' Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
Dim SmallResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128)
VB   C#
A Comparison between IronBarcode and ZXing.NET, Figure 13: Automatic Barcode Thumbnail Size Correction

Automatic Barcode Thumbnail Size Correction

Reading Barcodes from Imperfect Images

In real-world scenarios, we might want to read barcodes from imperfect images. They could be skewed images or photographs with digital noise. This would be impossible with most open-source .NET barcode generation and reading libraries. IronBarcode, on the other hand, makes reading barcodes from imperfect images a breeze.

We'll now look at the ReadASingleBarcode method. With its RotationCorrection parameter, IronBarcode attempts to de-skew and read barcodes from imperfect digital samples.

using IronBarCode;
using System;
using System.Drawing;
// All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
// * RotationCorrection   e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
// * ImageCorrection      e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
// * BarcodeEncoding      e.g. BarcodeEncoding.Code128,  Setting a specific Barcode format improves speed and reduces the risk of false positive results
// Example with a photo image
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
System.Drawing.Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte [] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);
using IronBarCode;
using System;
using System.Drawing;
// All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
// * RotationCorrection   e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
// * ImageCorrection      e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
// * BarcodeEncoding      e.g. BarcodeEncoding.Code128,  Setting a specific Barcode format improves speed and reduces the risk of false positive results
// Example with a photo image
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
System.Drawing.Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte [] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);
Imports IronBarCode
Imports System
Imports System.Drawing
' All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
' * RotationCorrection   e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
' * ImageCorrection      e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
' * BarcodeEncoding      e.g. BarcodeEncoding.Code128,  Setting a specific Barcode format improves speed and reduces the risk of false positive results
' Example with a photo image
Private PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels)
Private Value As String = PhotoResult.Value
Private Img As System.Drawing.Bitmap = PhotoResult.BarcodeImage
Private BarcodeType As BarcodeEncoding = PhotoResult.BarcodeType
Private Binary() As Byte = PhotoResult.BinaryValue
Console.WriteLine(PhotoResult.Value)
VB   C#
A Comparison between IronBarcode and ZXing.NET, Figure 14: Reading a Barcode From a Phone Camera

Reading a Barcode From a Phone Camera

IronBarcode can also read multiple barcodes at the same time. We get better results from IronBarcode when we create a list of documents and use the barcode reader to read numerous documents. Method ReadBarcodesMultithreaded for the barcode scanning process uses multiple threads and potentially all cores of your CPU and can be exponentially faster than reading barcodes one at a time.

// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs.  All threads are automatically managed by IronBarcode.
var ListOfDocuments = new [] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult [] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);
// Work with the results
foreach (var Result in BatchResults)
{
    string Value = Result.Value;
    //...
}
// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs.  All threads are automatically managed by IronBarcode.
var ListOfDocuments = new [] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult [] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);
// Work with the results
foreach (var Result in BatchResults)
{
    string Value = Result.Value;
    //...
}
' The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs.  All threads are automatically managed by IronBarcode.
Dim ListOfDocuments = { "Image1.png", "image2.JPG", "image3.pdf" }
Dim BatchResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments)
' Work with the results
For Each Result In BatchResults
	Dim Value As String = Result.Value
	'...
Next Result
VB   C#

Reading and Decoding QR Codes with ZXing.NET

To read the QR code files, add a ViewFile action method to your controller, as shown below.

public ActionResult ViewFile()
{
    List<KeyValuePair<string, string>> fileData = new List<KeyValuePair<string, string>>();
    KeyValuePair<string, string> data;

    string [] files = Directory.GetFiles(Server.MapPath("~/qrr"));
    foreach (string file in files)
    {
        // create a barcode reader instance
        IBarcodeReader reader = new BarcodeReader();
        // load a bitmap
        var barcodeBitmap = (Bitmap)Image.FromFile(Server.MapPath("~/qrr") + "/" + Path.GetFileName(file));
        // detect and decode the barcode inside the bitmap
        var result = reader.Decode(barcodeBitmap);
        // do something with the result
        data = new KeyValuePair<string, string>(result.ToString(), "/QR/" + Path.GetFileName(file));
        fileData.Add(data);
    }
    return View(fileData);
}
public ActionResult ViewFile()
{
    List<KeyValuePair<string, string>> fileData = new List<KeyValuePair<string, string>>();
    KeyValuePair<string, string> data;

    string [] files = Directory.GetFiles(Server.MapPath("~/qrr"));
    foreach (string file in files)
    {
        // create a barcode reader instance
        IBarcodeReader reader = new BarcodeReader();
        // load a bitmap
        var barcodeBitmap = (Bitmap)Image.FromFile(Server.MapPath("~/qrr") + "/" + Path.GetFileName(file));
        // detect and decode the barcode inside the bitmap
        var result = reader.Decode(barcodeBitmap);
        // do something with the result
        data = new KeyValuePair<string, string>(result.ToString(), "/QR/" + Path.GetFileName(file));
        fileData.Add(data);
    }
    return View(fileData);
}
Public Function ViewFile() As ActionResult
	Dim fileData As New List(Of KeyValuePair(Of String, String))()
	Dim data As KeyValuePair(Of String, String)

	Dim files() As String = Directory.GetFiles(Server.MapPath("~/qrr"))
	For Each file As String In files
		' create a barcode reader instance
		Dim reader As IBarcodeReader = New BarcodeReader()
		' load a bitmap
		Dim barcodeBitmap = CType(Image.FromFile(Server.MapPath("~/qrr") & "/" & Path.GetFileName(file)), Bitmap)
		' detect and decode the barcode inside the bitmap
		Dim result = reader.Decode(barcodeBitmap)
		' do something with the result
		data = New KeyValuePair(Of String, String)(result.ToString(), "/QR/" & Path.GetFileName(file))
		fileData.Add(data)
	Next file
	Return View(fileData)
End Function
VB   C#
A Comparison between IronBarcode and ZXing.NET, Figure 15: Reading and Decoding QR Code

Reading and Decoding QR Code

A Comparison between IronBarcode and ZXing.NET, Figure 16: Decoded QR Code

Decoded QR Code

Decoding a Barcode Inside a Bitmap

// create a barcode reader instance
BarcodeReader reader = new BarcodeReader();
// load a bitmap
var barcodeBitmap = (Bitmap)Image.LoadFrom("C:\\sample-barcode-image.png");
// detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
// do something with the result
if (result != null)
{
   txtDecoderType.Text = result.BarcodeFormat.ToString();
   txtDecoderContent.Text = result.Text;
}
// create a barcode reader instance
BarcodeReader reader = new BarcodeReader();
// load a bitmap
var barcodeBitmap = (Bitmap)Image.LoadFrom("C:\\sample-barcode-image.png");
// detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
// do something with the result
if (result != null)
{
   txtDecoderType.Text = result.BarcodeFormat.ToString();
   txtDecoderContent.Text = result.Text;
}
' create a barcode reader instance
Dim reader As New BarcodeReader()
' load a bitmap
Dim barcodeBitmap = CType(Image.LoadFrom("C:\sample-barcode-image.png"), Bitmap)
' detect and decode the barcode inside the bitmap
Dim result = reader.Decode(barcodeBitmap)
' do something with the result
If result IsNot Nothing Then
   txtDecoderType.Text = result.BarcodeFormat.ToString()
   txtDecoderContent.Text = result.Text
End If
VB   C#

ZXing Decoder Online

ZXing Decoder Online is a barcode and QR code scanner available online that supports decoding. Upload a PNG or other format of the QR code image, and it will begin decoding. Similarly, you can generate a QR code for any data. Most of the time, that information will be a URL or text you want to encode in a QR code.

Navigate to the ZXing Decoder website.

A Comparison between IronBarcode and ZXing.NET, Figure 17: Decoded QR Code

ZXing Decoder Website

A Comparison between IronBarcode and ZXing.NET, Figure 18: Decoded QR Code

ZXing Decode Result

Pricing and Licensing

The ZXing.NET library is a free open-source library which allows you to build barcode reading applications, but is build on an Apache license which doesn't allow it to be freely used for commercial purposes.

A developer's license for IronBarcode is offered without charge. IronBarcode has a unique pricing scheme: the Lite bundle starts at $749 with no additional costs. SaaS and OEM items may also be distributed again. Each license includes a perpetual license, dev/staging/production validity, a 30-day money-back guarantee, and a year of software support and upgrades (one-time purchase). Visit this page to view IronBarcode's complete pricing and license information.

Why Choose IronBarcode?

IronBarcode includes an easy-to-use API for developers to read and write barcodes in .NET, which optimizes accuracy and a low error rate in real-world use cases.

The BarcodeWriter class, for example, will validate and correct 'checksums' on UPCA and UPCE barcodes. It will also 'zero-pad' numbers too short to be entered into a specific numeric format. If your data is incompatible with the specified data format, IronBarcode will notify the developer of a more suitable barcode format that they may use.

IronBarcode excels at reading barcodes when the barcode has been scanned or read from a photographic image in other words, when the image isn't perfect graphically and isn't a machine-generated screenshot.

How is IronBarcode Different from ZXing.NET?

IronBarcode is built from the ZXing.NET (Zebra Crossing) core, with improved processing capability. It comes with an easy-to-use API and a low error rate compared to the ZXing.NET core library. Not only that, but IronBarcode also supports a wider range of barcode formats than the usual ZXing.NET library supports.

IronBarcode is a more improved version of ZXing.NET, giving the user the platform for commercial use and the possibility of using the same package on multiple platforms. It also has full tech support, always ready to help you wherever needed.

IronBarcode includes automatic rotation, perspective correction, and digital noise correction and can detect the type of barcode encoded in an image.

Conclusion

In conclusion, IronBarcode is a versatile .NET software library and C# QR Code generator for reading a wide range of barcode formats, whether they are screenshots, photographs, scans, or other imperfect real-world images.

IronBarcode is one of the most effective libraries for creating and identifying barcodes. In terms of creating and identifying barcodes, it is also among the swiftest libraries. Different operating systems are compatible with the library. It is easy to design and supports a wide range of barcode formats. Additionally, various symbols, formats, and characters are supported.

ZXing.NET barcode is a powerful library that generates and recognizes barcodes in various image formats. We can read and create images in a variety of formats. ZXing.NET also allows you to change the appearance of a barcode, altering its height, width, barcode text, and so on.

In comparison to ZXing.NET, IronBarcode packages offer a reliable licensing and support. IronBarcode costs $749. Although ZXing is free, it gives you no possibility for commercial use and also lacks an all present support. In addition to being more flexible than ZXing.NET, IronBarcode solution also has more functionality too. Thus, it is evident that IronBarcode has a strong edge over ZXing.NET.

When comparing the processing times for recognizing and generating barcodes, IronBarcode outperforms ZXing.NET. IronBarcode also has several properties that allow us to read barcodes from different image formats and PDF documents. It also allows us to include images within the barcode or QR code, which is not available in any other library.

IronBarcode is free for early stages of development. You can acquire a free trial for production level or commercial use. According to the requirements of the developer, IronBarcode offers three pricing tiers. You can pick the solution that best satisfies your demands. You may now get a suite of five Iron Software products for the price of two Iron Software items. Visit this website for further information.

< PREVIOUS
A Comparison Between ZXing Decoder & IronBarcode
NEXT >
A Comparison between IronBarcode and Aspose.Barcode

Ready to get started? Version: 2024.11 just released

Free NuGet Download Total downloads: 1,290,353 View Licenses >