Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
A barcode is a type of machine-readable code that stores information about various items in the form of lines and spaces arranged in a pattern. Barcodes are made up of a series of parallel bars that are used to encode data. These bars make up what is called a "barcode" or "barcode symbol" which can be read by a barcode scanner (sometimes just called a "scanner"). All barcodes have four parts:
Barcodes are the most efficient way to identify products in a retail environment. Every product has a unique barcode that can easily be scanned for inventory control or for price verification. Nowadays, barcodes are not just used as an efficient way of identifying products in a retail environment; they have become an important aspect of our everyday life because they are used to store information electronically and manage consumer identities.
In this article, we are going to compare two popular barcode libraries:
Both of these libraries can be used for the generation and recognition of barcodes, provide support for all .NET frameworks, and allow you to save the barcode images.
We will look at how to generate a barcode in C# .NET with the IronBarcode library through an example. We'll see how easy it is to create a barcode, style it, and then export it using IronBarcode.
Open Visual Studio, and then go to the file menu. Select a new project and then select Console Application/Windows Forms/WPF Application. IronBarcode can be used on all types of applications, including Webform/MVC/MVC Core.
Enter the project name and select the file path in the appropriate text box. Click the Create button and select the required .NET Framework. The project will now be generated with the structure for the selected application, and, if you have selected the console application, it will open the Program.cs
file where you can enter the code and build/run the application.
The IronBarcode Library can be downloaded and installed in four ways:
The Visual Studio software provides a NuGet Package Manager option to install the package directly to the solution. The screenshot below shows how to open the NuGet Package Manager.
It provides a search box to show the list of packages from the NuGet website. In the package manager, we need to search for the keyword "Barcode," as in the screenshot below:
From the above image, we will get the list of related search results. We need to select the required option to install the package to the solution.
In Visual Studio tools, go to Tools -> NuGet Package Manager -> Package Manager Console.
Enter the following line in the console tab:
Install-Package BarCode
Now the package will download/install to the current project and be ready to use.
The third way is to download the package directly from the website.
Click the link to download the latest package from the website. After the download, follow the steps below to add the package to the project.
After installing the Iron Barcode library, you can add barcode functionality to your .NET framework by using it through the NuGet package or downloading the .NET Barcode DLL.
Install-Package BarCode
In the following example, we will see how a barcode containing numerical or text content can be created using a few lines of code with IronBarcode.
// Generate a Simple BarCode image and save as PNG using IronBarCode
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 IronBarCode
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 IronBarCode
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")
In the first step, we create the barcode by specifying its value, and the barcode format we will be using is from the IronBarCode.BarcodeWriterEncoding
enum. We can then save it as an image, or as a System.Drawing.Image
, or as a Bitmap
object. That's all the code it takes! The final line of code opens the barcode PNG in the default image viewer so that you can see it with your own eyes.
Although the previous example was effective, in the real world we may wish to do more. In the following example, we add annotations to the barcode, set the font, display its value below it, add margins, change the barcode color, and then save it, all quite simply in C#. We can also choose to export to HTML or PDF instead of an image if that is more appropriate for our application.
using IronBarCode;
using System.Drawing;
// Styling a QR code and adding annotation text
var MyBarCode = IronBarCode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode);
MyBarCode.AddAnnotationTextAboveBarcode("Product URL:");
MyBarCode.AddBarcodeValueTextBelowBarcode();
MyBarCode.SetMargins(100);
MyBarCode.ChangeBarCodeColor(Color.Purple);
// Save as HTML
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
using IronBarCode;
using System.Drawing;
// Styling a QR code and adding annotation text
var MyBarCode = IronBarCode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode);
MyBarCode.AddAnnotationTextAboveBarcode("Product URL:");
MyBarCode.AddBarcodeValueTextBelowBarcode();
MyBarCode.SetMargins(100);
MyBarCode.ChangeBarCodeColor(Color.Purple);
// Save as HTML
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
Imports IronBarCode
Imports System.Drawing
' Styling a QR code and adding annotation text
Private MyBarCode = IronBarCode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode)
MyBarCode.AddAnnotationTextAboveBarcode("Product URL:")
MyBarCode.AddBarcodeValueTextBelowBarcode()
MyBarCode.SetMargins(100)
MyBarCode.ChangeBarCodeColor(Color.Purple)
' Save as HTML
MyBarCode.SaveAsHtmlFile("MyBarCode.html")
The code should be self-explanatory, but if not, we encourage you to read the GeneratedBarcode class documentation within the API Reference.
Reading a barcode or QR code in .NET is incredibly easy using the IronBarcode class library with .NET Barcode Reader. In our first example, we can see how to read this barcode with one line of code.
Barcode Image to be Scanned with C#
We can extract its value, its image, its encoding type, its binary data (if any), and then output that 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
We can add the TryHarder
variable to the QuicklyReadOneBarcode
method. This makes it try harder, literally taking more time but scanning deeper for a QR code that might be obscured, corrupted, or at a skewed angle.
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("TryHarderQR.png", BarcodeEncoding.QRCode | BarcodeEncoding.Code128, true);
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("TryHarderQR.png", BarcodeEncoding.QRCode | BarcodeEncoding.Code128, true);
Dim Result As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("TryHarderQR.png", BarcodeEncoding.QRCode Or BarcodeEncoding.Code128, True)
It can now read this skewed QR Code:
Scanning a QR code rotated through 45 degrees with C#
You will see that we can specify the barcode encoding(s) that we are looking for or specify multiple formats. Doing so greatly improves barcode reading performance and accuracy. The pipe character (|) or 'Bitwise OR' is used to specify multiple formats simultaneously. The same can be achieved, but with a higher degree of specificity, by using the visual method or the BarcodeReader.ReadASingleBarcode
method component mode.
In real-world use cases, we may wish to read barcodes that are not perfect screenshots. They may be imperfect images, scans, or photographs, and contain digital noise or be skewed. With most conventional open-source .NET barcode generators and reader libraries, this would be impossible. However, this Barcode Reader in C# makes it incredibly straightforward. We will look at the TryHarder
method of QuicklyReadOneBarcode
. This single parameter causes Iron Barcode to try to de-skew and read barcodes from imperfect digital samples.
We will set the specific barcode rotation correction and barcode image correction to correct for the digital noise and the skew, perspective, and rotation that we might reasonably expect from a cellphone camera.
Reading a barcode from a phone camera in C#
using IronBarCode;
using System;
using System.Drawing;
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte[] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);
using IronBarCode;
using System;
using System.Drawing;
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte[] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);
Imports IronBarCode
Imports System
Imports System.Drawing
Private PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels)
Private Value As String = PhotoResult.Value
Private Img As Bitmap = PhotoResult.BarcodeImage
Private BarcodeType As BarcodeEncoding = PhotoResult.BarcodeType
Private Binary() As Byte = PhotoResult.BinaryValue
Console.WriteLine(PhotoResult.Value)
In our final example, we will see that we can create, style, and export a barcode with a single line of code. IronBarcode implements an optional fluent API similar to System.Linq. By chaining method calls, we first create a barcode, then set its margins, and finally export it to Bitmap in a single line. This can be highly convenient, making the code easier to read.
Free Spire.Barcode for .NET is a free and professional barcode API specially designed for .NET developers (C#, VB.NET, ASP.NET) to generate and read 1D & 2D barcodes. Developers and programmers can use Spire.BarCode to add enterprise-level barcode formats to their .NET applications, ASP.NET WinForms, and Web Services quickly and easily. Free Spire.Barcode for .NET provides a very easy way to integrate barcode processing. Spire.BarCode supports various common image formats, such as Bitmap, JPG, PNG, EMF, TIFF, GIF, and WMF. It also provides support for QR codes.
The first thing we need to do is install the Spire library to add barcode functionality to the .NET framework. We can do this by using the NuGet package. As we did with IronBarcode, the process is the same — follow the same steps and just type "Spire Barcode" and add the packages to a project.
The library provides methods to create barcode images. It is an overloaded method. Here we list the definitions of the methods that will be used in the code to test the library's performance.
using Spire.Barcode;
using System.Drawing;
namespace QRCode
{
class Program
{
static void Main(string[] args)
{
BarcodeSettings settings = new BarcodeSettings
{
Type = BarCodeType.QRCode,
Data = "Hello world",
Data2D = "Hello 123456789",
QRCodeDataMode = QRCodeDataMode.AlphaNumber,
X = 1.0f,
QRCodeECL = QRCodeECL.H
};
BarCodeGenerator generator = new BarCodeGenerator(settings);
Image image = generator.GenerateImage();
image.Save("QRCode.png");
}
}
}
using Spire.Barcode;
using System.Drawing;
namespace QRCode
{
class Program
{
static void Main(string[] args)
{
BarcodeSettings settings = new BarcodeSettings
{
Type = BarCodeType.QRCode,
Data = "Hello world",
Data2D = "Hello 123456789",
QRCodeDataMode = QRCodeDataMode.AlphaNumber,
X = 1.0f,
QRCodeECL = QRCodeECL.H
};
BarCodeGenerator generator = new BarCodeGenerator(settings);
Image image = generator.GenerateImage();
image.Save("QRCode.png");
}
}
}
Imports Spire.Barcode
Imports System.Drawing
Namespace QRCode
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim settings As New BarcodeSettings With {
.Type = BarCodeType.QRCode,
.Data = "Hello world",
.Data2D = "Hello 123456789",
.QRCodeDataMode = QRCodeDataMode.AlphaNumber,
.X = 1.0F,
.QRCodeECL = QRCodeECL.H
}
Dim generator As New BarCodeGenerator(settings)
Dim image As Image = generator.GenerateImage()
image.Save("QRCode.png")
End Sub
End Class
End Namespace
The produced QR barcode image looks as follows.
Create a QR Code in C#
// Generate the barcode based on the barcode control settings
BarCodeGenerator generator = new BarCodeGenerator(this.barCodeControl1);
Image barcode = generator.GenerateImage();
// Save the barcode as an image
barcode.Save("barcode.png");
// Generate the barcode based on the barcode control settings
BarCodeGenerator generator = new BarCodeGenerator(this.barCodeControl1);
Image barcode = generator.GenerateImage();
// Save the barcode as an image
barcode.Save("barcode.png");
' Generate the barcode based on the barcode control settings
Dim generator As New BarCodeGenerator(Me.barCodeControl1)
Dim barcode As Image = generator.GenerateImage()
' Save the barcode as an image
barcode.Save("barcode.png")
There are two important classes — BarCodeControl
and BarCodeGenerator
in this method. BarCodeControl
stores information about barcodes. BarCodeGenerator
is the class to generate barcode images. Its constructor takes one parameter — a BarCodeControl
instance. It has a method called GenerateImage()
whose return value is the Image
object to generate an image.
The barcode scanner is the class to scan barcode images. Call its method Scan
with the Bitmap
object containing the barcode image; it returns a string[]
value where the scanning result is stored. The class BarcodeScanner
is used to scan barcode images in this code. It can store and add enterprise-level barcodes in VB.NET and C#.
Here is the code:
private void btnScan_Click(object sender, EventArgs e)
{
// Scan the barcode
string[] datas = Spire.Barcode.BarcodeScanner.Scan("barcode.png");
// Show the scan result
this.TextB_ScanResult.Text = datas[0];
}
private void btnScan_Click(object sender, EventArgs e)
{
// Scan the barcode
string[] datas = Spire.Barcode.BarcodeScanner.Scan("barcode.png");
// Show the scan result
this.TextB_ScanResult.Text = datas[0];
}
Private Sub btnScan_Click(ByVal sender As Object, ByVal e As EventArgs)
' Scan the barcode
Dim datas() As String = Spire.Barcode.BarcodeScanner.Scan("barcode.png")
' Show the scan result
Me.TextB_ScanResult.Text = datas(0)
End Sub
The 30-day money-back guarantee: Upon purchase, if the license does not work, you can get your money back within 30 days.
Easy integration: The integration of IronPDF with your project and environment is straightforward and can be achieved with a single line of code when using the NuGet Package. Integration can also be done via direct download.
Perpetual licensing: Each license is purchased once and does not require renewal.
Free support & product updates: Every license comes with a year of free product updates and support from the team behind the product, with the possibility to purchase extensions at any time.
Immediate licenses: Registered license keys are sent as soon as payment is received.
All licenses are perpetual and apply to development, staging, and production.
The Lite Package:
This package allows a single software developer to utilize Iron Software at a single location. It can be used in a single web application, intranet application, or desktop software program. Licenses are non-transferable and cannot be shared outside of an organization or an agency/client relationship. Distribution rights do not extend to OEM redistribution and SaaS unless additional coverage is purchased.
Pricing: Starts from $749 per year.
Professional License:
This package allows up to ten software developers to utilize Iron Software in single locations, up to a maximum of ten. It can be used in as many websites, intranet applications, or desktop software applications as desired. Licenses are non-transferable and cannot be shared outside of an organization or an agency/client relationship. Distribution rights do not extend to OEM redistribution and SaaS unless additional coverage is purchased.
Pricing: Starts from $999 per year.
Unlimited License:
This allows unlimited software developers in an organization to utilize Iron Software in unlimited locations. It can be used in as many websites, intranet applications, or desktop software applications as desired. Licenses are non-transferable and cannot be shared outside of an organization or an agency/client relationship. Distribution rights do not extend to OEM redistribution and SaaS unless additional coverage is purchased.
Pricing: Starts from $2999 per year.
Royalty-Free Redistribution: Allows distribution of Iron Software as part of various commercial products (without royalties), based on the number of projects covered by the base license. It also allows deployment within SaaS software services, based on the projects covered by the base license.
Pricing: Starts from $1599 per year.
Uninterrupted product support and updates: Provides access to product updates, security feature upgrades, and engineering team support.
Pricing: Starts from $399 per year.
Create a QR Code in C#
Support is paid, and subscriptions are one-time payments. Only the OEM subscription works for public-facing websites and cloud-based applications.
Developer Subscription:
This package authorizes one developer to use the product to create unlimited applications that can be deployed at one geographic location within an organization (internal use only). It does not allow distribution to third parties or the deployment of custom applications on public-facing websites or for SaaS/PaaS/IaaS projects.
Pricing: Starts from $898 per year.
Developer OEM Subscription:
This package authorizes one developer to create an unlimited number of custom applications using the product, and these applications are allowed to be distributed in any form to any number of geographic locations.
Pricing: Starts from $3395 per year.
Site Enterprise Subscription:
This authorizes up to 10 developers to create unlimited applications, which can be deployed at up to 10 geographic locations. It does not allow the distribution of custom applications to public-facing websites, or SaaS/PaaS/IaaS projects.
Pricing: Starts from $5301 per year.
Site OEM Subscription:
This authorizes up to 50 developers to create an unlimited number of custom applications using the product, and these applications are allowed to be distributed in any form to any number of geographic locations.
Pricing: Starts from $10187 per year.
The IronBarcode Lite package includes one developer package with one year of support and costs around $749, whereas the Spire Developer OEM Subscription, which includes one developer package, costs $3394, with all updates, major releases, and technical support for one year; without releases and technical support, it costs $1695. The IronPDF Professional package, which includes 10 developer packages and one year of support, costs $999, while the Spire Site OEM Subscription, including 10 developer packages, costs $10187 per year with all updates, major releases, and technical support for one year, and without releases and updates, it costs $6558.
Both the IronPDF Lite and Professional packages have SaaS service or OEM, as well as a five-year support option. The Lite version includes one developer package with five-year support and with SaaS and OEM service at a cost of $2897USD, whereas Spire has SaaS service or OEM and a one-year support option. The IronPDF Professional version, including a 10-developer package with five years of support and SaaS and OEM service, costs $3397, whereas the Spire package for 10 developers with one year of support and with SaaS and OEM service costs $10187.
IronBarcode is used to generate enterprise-level barcode formats of barcode images. It enables developers to rotate barcode images, as well as create barcode image borders to assist in formatting barcode images further. IronBarcode provides reliable barcode generation compared to other generators and generates high-quality barcode images. We can obtain a desired output image format with IronBarcode, and the generated barcode images are of high quality because we can create, style, and export a barcode with a single line of code. Barcode developers will find it easily integrates with other .NET applications and allows for different barcode types to be recognized. The component model of the library is efficient—for each component mode, developers can generate barcodes with different styles and formats. The simple code is just one line, and the recognition functionality is superior in IronBarcode. The API mode makes it more reliable than other generators.
Spire.Barcode for .NET provides a straightforward way to integrate barcode processing. With just one line of code, developers can create and read 1D & 2D barcodes. Spire.Barcode supports various common image formats, such as Bitmap, JPG, PNG, EMF, TIFF, GIF, and WMF. Therefore, developers can easily create barcode images, and can integrate barcode generation and creation with minimal code.
IronBarcode packages provide better licenses and support compared to Spire.Barcode, which is also more expensive. IronBarcode starts from $749 while Spire.Barcode starts from $898, making IronBarcode more cost-effective. IronBarcode also provides more features than Spire.Barcode and better support and a money-back guarantee. IronBarcode offers long-term support and seamlessly integrates with API mode .NET applications. It supports easy integration with new documents (C#, VB.NET), and it generates multiple barcode formats.
So, why wait? Get the free trial! You can obtain the License here and begin straightaway.
Barcodes are used to encode data that can be easily scanned and read by barcode scanners. They are primarily used for inventory control and price verification in retail environments, as well as to store information electronically and manage consumer identities.
A barcode consists of four main components: the Start Character, Tolerances (changes allowed for widths and heights), Data Characters (representing the encoded information), and the Stop Character.
Spire Barcode and IronBarcode are libraries used for the generation and recognition of barcodes. They support .NET frameworks and allow users to save barcode images.
IronBarcode can be installed via Visual Studio's NuGet Package Manager, the Visual Studio Command-Line, direct download from the NuGet website, or from the IronBarcode website.
IronBarcode allows users to create, style, and export barcodes. It supports various barcode formats, adds annotations, changes barcode colors, and exports images to formats such as HTML or PDF.
IronBarcode offers different license options, including Lite, Professional, and Unlimited, with prices starting from a certain amount per year. Licenses are perpetual and come with a year of free product updates and support.
Spire.Barcode provides methods for creating barcode images and supports various image formats. It can generate and read 1D & 2D barcodes and integrates easily with .NET applications.
Spire.Barcode generally has higher pricing compared to IronBarcode. IronBarcode is more cost-effective starting from a lower price point, with better support and licensing options.
IronBarcode offers reliable barcode generation with high-quality images, easy integration, and multiple barcode format support. It provides better licensing, support, and cost-effectiveness compared to competitors like Spire.Barcode.