# Barcodes & QRs in C# & VB.NET Applications
Reading and writing barcodes in C# and all other .NET languages is an easy process with our IronBarcode software library.
## Install IronBarcode
The first step in the journey will be installing IronBarcode, which can be done by downloading from NuGet or by [downloading the DLL](https://www.nuget.org/packages/Barcode/).
To install the IronBarcode NuGet package, you could use the NuGet Package Manager for Visual Studio:
```shell
:ProductInstall
```
Alternatively, you could also install with the .NET CLI:
```shell
:InstallCmd dotnet add package IronBarCode
```
## Reading a Barcode or QR Code
Reading a barcode only takes one line of code with IronBarcode.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-1.cs
```
With this one line of code, you have the ability to detect and scan all types of barcodes from the input document with exceptional performance - everything you need in one step! This method supports a wide range of image formats, such as JPEG, PNG, and BMP, as well as PDFs and multi-frame formats like GIF and TIFF. For enhanced performance, customizable configuration options are available.
To improve reading speed, you can create a `BarcodeReaderOptions` object with the `Speed` setting configured for better performance. The default is `Balanced`, but the `Faster` option is available to skip certain checks.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-2.cs
```
You can also set the `ScanMode` to `OnlyBasicScan` to optimize the reading process.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-3.cs
```
Other configurations include specifying the barcode formats to scan for, which can help speed up processing by reducing unnecessary scans.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-4.cs
```
## Writing Barcodes
To write barcodes using IronBarcode, we use the `BarcodeWriter` class.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-5.cs
```
## Styling Barcodes
IronBarcode offers several options to manipulate the visual depiction of a barcode.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-7.cs
```
## Exporting Barcodes as HTML
IronBarcode can export barcodes as HTML documents or as part of HTML content.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-8.cs
```
## Generating QR Codes
For QR codes, use the `QRCodeWriter` class which provides additional configuration for QR-specific features like error correction.
```csharp
:path=/static-assets/barcode/content-code-examples/get-started/get-started-9.cs
```
## Supported Barcode Formats
IronBarcode supports a wide variety of commonly used barcode formats for both reading and writing:
- **QR**, **Micro QR**, and **Rectangular Micro QR (rMQR)** codes.
- Other two-dimensional barcodes such as **Aztec**, **Data Matrix**, **MaxiCode**, and **PDF417**.
- Stacked linear barcodes such as **Databar**.
- Conventional one-dimensional barcode formats such as **UPC-A**, **UPC-E**, **EAN-8**, **EAN-13**, **Codabar**, **ITF**, **MSI**, and **Plessey**.
## Why Choose IronBarcode?
IronBarcode offers a friendly, easy-to-use API for developers to read and write barcodes for .NET, which optimizes for accuracy, precision, and speed in real-world use cases.
The `BarcodeWriter` class, for example, automatically validates and corrects 'checksums' on UPCA and UPCE barcodes, and handles numeric format constraints. IronBarcode assists developers in choosing the most suitable barcode format for their data.
The library is robust, with image pre-processing techniques like automatic rotation and image denoising to maximize barcode detection success rates.
## Moving Forward
To get the most out of IronBarcode, we encourage you to read the tutorials within this documentation section, and to visit us on [GitHub](https://github.com/iron-software).
Reading and writing barcodes in C# and all other .NET languages is an easy process with our IronBarcode software library.
Install IronBarcode
The first step in the journey will be installing IronBarcode, which can be done by downloading from NuGet or by downloading the DLL.
To install the IronBarcode NuGet package, you could use the NuGet Package Manager for Visual Studio:
PM > Install-Package BarCode
Install-Package BarCode
Alternatively, you could also install with the .NET CLI:
> dotnet add package IronBarCode
dotnet add package IronBarCode
Reading a Barcode or QR Code
Reading a barcode only takes one line of code with IronBarcode.
using IronBarCode;BarcodeResults results = BarcodeReader.Read("QuickStart.jpg");if (results != null){ foreach (BarcodeResult result in results) {Console.WriteLine(result.Text); }}
using IronBarCode;
BarcodeResults results = BarcodeReader.Read("QuickStart.jpg");
if (results != null)
{
foreach (BarcodeResult result in results)
{
Console.WriteLine(result.Text);
}
}
ImportsIronBarCodePrivate results AsBarcodeResults = BarcodeReader.Read("QuickStart.jpg")If results IsNot Nothing Then For Each result AsBarcodeResultIn resultsConsole.WriteLine(result.Text) Next resultEnd If
Imports IronBarCode
Private results As BarcodeResults = BarcodeReader.Read("QuickStart.jpg")
If results IsNot Nothing Then
For Each result As BarcodeResult In results
Console.WriteLine(result.Text)
Next result
End If
With this one line of code, you have the ability to detect and scan all types of barcodes from the input document with exceptional performance - everything you need in one step! This method supports a wide range of image formats, such as JPEG, PNG, and BMP, as well as PDFs and multi-frame formats like GIF and TIFF. For enhanced performance, customizable configuration options are available.
To improve reading speed, you can create a BarcodeReaderOptions object with the Speed setting configured for better performance. The default is Balanced, but the Faster option is available to skip certain checks.
using IronBarCode;BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions(){ExpectMultipleBarcodes = false,ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,CropArea = new System.Drawing.Rectangle(100, 200, 300, 400),};BarcodeResults result = BarcodeReader.Read("QuickStart.jpg", myOptionsExample);if (result != null){Console.WriteLine(result.First().Text);}
using IronBarCode;
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = false,
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
CropArea = new System.Drawing.Rectangle(100, 200, 300, 400),
};
BarcodeResults result = BarcodeReader.Read("QuickStart.jpg", myOptionsExample);
if (result != null)
{
Console.WriteLine(result.First().Text);
}
ImportsIronBarCodePrivate myOptionsExample As New BarcodeReaderOptions() With { .ExpectMultipleBarcodes = False, .ExpectBarcodeTypes = BarcodeEncoding.QRCodeOrBarcodeEncoding.Code128, .CropArea = New System.Drawing.Rectangle(100, 200, 300, 400)}Private result AsBarcodeResults = BarcodeReader.Read("QuickStart.jpg", myOptionsExample)If result IsNot Nothing ThenConsole.WriteLine(result.First().Text)End If
Imports IronBarCode
Private myOptionsExample As New BarcodeReaderOptions() With {
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128,
.CropArea = New System.Drawing.Rectangle(100, 200, 300, 400)
}
Private result As BarcodeResults = BarcodeReader.Read("QuickStart.jpg", myOptionsExample)
If result IsNot Nothing Then
Console.WriteLine(result.First().Text)
End If
You can also set the ScanMode to OnlyBasicScan to optimize the reading process.
using IronBarCode;BarcodeResults results = BarcodeReader.Read("MultipleBarcodes.png");// Loop through the resultsforeach (BarcodeResult result in results){ string value = result.Value; Bitmap img = result.BarcodeImage; BarcodeEncoding barcodeType = result.BarcodeType; byte[] binary = result.BinaryValue;Console.WriteLine(result.Value);}
using IronBarCode;
BarcodeResults results = BarcodeReader.Read("MultipleBarcodes.png");
// Loop through the results
foreach (BarcodeResult result in results)
{
string value = result.Value;
Bitmap img = result.BarcodeImage;
BarcodeEncoding barcodeType = result.BarcodeType;
byte[] binary = result.BinaryValue;
Console.WriteLine(result.Value);
}
ImportsIronBarCodePrivate results AsBarcodeResults = BarcodeReader.Read("MultipleBarcodes.png")' Loop through the resultsFor Each result AsBarcodeResultIn results Dim value AsString = result.Value Dim img AsBitmap = result.BarcodeImage Dim barcodeType AsBarcodeEncoding = result.BarcodeType Dim binary() AsByte = result.BinaryValueConsole.WriteLine(result.Value)Next result
Imports IronBarCode
Private results As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.png")
' Loop through the results
For Each result As BarcodeResult In results
Dim value As String = result.Value
Dim img As Bitmap = result.BarcodeImage
Dim barcodeType As BarcodeEncoding = result.BarcodeType
Dim binary() As Byte = result.BinaryValue
Console.WriteLine(result.Value)
Next result
Other configurations include specifying the barcode formats to scan for, which can help speed up processing by reducing unnecessary scans.
using IronBarCode;BarcodeResults pagedResults = BarcodeReader.Read("MultipleBarcodes.pdf");// Loop through the resultsforeach (BarcodeResult result in pagedResults){ int pageNumber = result.PageNumber; string value = result.Value; Bitmap img = result.BarcodeImage; BarcodeEncoding barcodeType = result.BarcodeType; byte[] binary = result.BinaryValue;Console.WriteLine(result.Value);}// or from a multi-page TIFF scan with image correction:BarcodeResults multiFrameResults = BarcodeReader.Read(inputImage: "Multiframe.tiff", new BarcodeReaderOptions{Speed = ReadingSpeed.Detailed,ExpectMultipleBarcodes = true,ExpectBarcodeTypes = BarcodeEncoding.Code128,Multithreaded = false,RemoveFalsePositive = false,ImageFilters = null});
using IronBarCode;
BarcodeResults pagedResults = BarcodeReader.Read("MultipleBarcodes.pdf");
// Loop through the results
foreach (BarcodeResult result in pagedResults)
{
int pageNumber = result.PageNumber;
string value = result.Value;
Bitmap img = result.BarcodeImage;
BarcodeEncoding barcodeType = result.BarcodeType;
byte[] binary = result.BinaryValue;
Console.WriteLine(result.Value);
}
// or from a multi-page TIFF scan with image correction:
BarcodeResults multiFrameResults = BarcodeReader.Read(inputImage: "Multiframe.tiff", new BarcodeReaderOptions
{
Speed = ReadingSpeed.Detailed,
ExpectMultipleBarcodes = true,
ExpectBarcodeTypes = BarcodeEncoding.Code128,
Multithreaded = false,
RemoveFalsePositive = false,
ImageFilters = null
});
ImportsIronBarCodePrivate pagedResults AsBarcodeResults = BarcodeReader.Read("MultipleBarcodes.pdf")' Loop through the resultsFor Each result AsBarcodeResultIn pagedResults Dim pageNumber AsInteger = result.PageNumber Dim value AsString = result.Value Dim img AsBitmap = result.BarcodeImage Dim barcodeType AsBarcodeEncoding = result.BarcodeType Dim binary() AsByte = result.BinaryValueConsole.WriteLine(result.Value)Next result' or from a multi-page TIFF scan with image correction:Dim multiFrameResults AsBarcodeResults = BarcodeReader.Read(inputImage:= "Multiframe.tiff", New BarcodeReaderOptionsWith { .Speed = ReadingSpeed.Detailed, .ExpectMultipleBarcodes = True, .ExpectBarcodeTypes = BarcodeEncoding.Code128, .Multithreaded = False, .RemoveFalsePositive = False, .ImageFilters = Nothing})
Imports IronBarCode
Private pagedResults As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.pdf")
' Loop through the results
For Each result As BarcodeResult In pagedResults
Dim pageNumber As Integer = result.PageNumber
Dim value As String = result.Value
Dim img As Bitmap = result.BarcodeImage
Dim barcodeType As BarcodeEncoding = result.BarcodeType
Dim binary() As Byte = result.BinaryValue
Console.WriteLine(result.Value)
Next result
' or from a multi-page TIFF scan with image correction:
Dim multiFrameResults As BarcodeResults = BarcodeReader.Read(inputImage:= "Multiframe.tiff", New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Detailed,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.Code128,
.Multithreaded = False,
.RemoveFalsePositive = False,
.ImageFilters = Nothing
})
Writing Barcodes
To write barcodes using IronBarcode, we use the BarcodeWriter class.
using IronBarCode;GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);myBarcode.SaveAsImage("myBarcode.png");
using IronBarCode;
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
myBarcode.SaveAsImage("myBarcode.png");
Imports IronBarCode
Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128)
myBarcode.SaveAsImage("myBarcode.png")
Styling Barcodes
IronBarcode offers several options to manipulate the visual depiction of a barcode.
using IronBarCode;GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);myBarcode.AddAnnotationTextAboveBarcode("Product URL:");myBarcode.AddBarcodeValueTextBelowBarcode();myBarcode.SetMargins(100);myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.Purple);// All major image formats supported as well as PDF and HTMLmyBarcode.SaveAsPng("myBarcode.png");
using IronBarCode;
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
myBarcode.AddAnnotationTextAboveBarcode("Product URL:");
myBarcode.AddBarcodeValueTextBelowBarcode();
myBarcode.SetMargins(100);
myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.Purple);
// All major image formats supported as well as PDF and HTML
myBarcode.SaveAsPng("myBarcode.png");
ImportsIronBarCodePrivate myBarcode AsGeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128)myBarcode.AddAnnotationTextAboveBarcode("Product URL:")myBarcode.AddBarcodeValueTextBelowBarcode()myBarcode.SetMargins(100)myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.Purple)' All major image formats supported as well as PDF and HTMLmyBarcode.SaveAsPng("myBarcode.png")
Imports IronBarCode
Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128)
myBarcode.AddAnnotationTextAboveBarcode("Product URL:")
myBarcode.AddBarcodeValueTextBelowBarcode()
myBarcode.SetMargins(100)
myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.Purple)
' All major image formats supported as well as PDF and HTML
myBarcode.SaveAsPng("myBarcode.png")
Exporting Barcodes as HTML
IronBarcode can export barcodes as HTML documents or as part of HTML content.
using IronBarCode;QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf");
using IronBarCode;
QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf");
For QR codes, use the QRCodeWriter class which provides additional configuration for QR-specific features like error correction.
using IronBarCode;using IronSoftware.Drawing;QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo);myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf");
using IronBarCode;
using IronSoftware.Drawing;
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo);
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf");
ImportsIronBarCodeImportsIronSoftware.DrawingPrivate qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")Private myQRCodeWithLogo AsGeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo)myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf")
Imports IronBarCode
Imports IronSoftware.Drawing
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo)
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf")
Supported Barcode Formats
IronBarcode supports a wide variety of commonly used barcode formats for both reading and writing:
QR, Micro QR, and Rectangular Micro QR (rMQR) codes.
Other two-dimensional barcodes such as Aztec, Data Matrix, MaxiCode, and PDF417.
Stacked linear barcodes such as Databar.
Conventional one-dimensional barcode formats such as UPC-A, UPC-E, EAN-8, EAN-13, Codabar, ITF, MSI, and Plessey.
Why Choose IronBarcode?
IronBarcode offers a friendly, easy-to-use API for developers to read and write barcodes for .NET, which optimizes for accuracy, precision, and speed in real-world use cases.
The BarcodeWriter class, for example, automatically validates and corrects 'checksums' on UPCA and UPCE barcodes, and handles numeric format constraints. IronBarcode assists developers in choosing the most suitable barcode format for their data.
The library is robust, with image pre-processing techniques like automatic rotation and image denoising to maximize barcode detection success rates.
Moving Forward
To get the most out of IronBarcode, we encourage you to read the tutorials within this documentation section, and to visit us on GitHub.
Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.