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
In this tutorial, we delve into reading multiple barcodes at once using the Iron Barcode library in C#. We start by setting up a project in Visual Studio and ensuring the Iron Barcode library is downloaded through the NuGet package manager. The tutorial emphasizes the importance of importing the library at the top of the code using the using
keyword. The core of the process involves setting the AcceptMultipleBarcodes
property to true and focusing on one-dimensional barcodes like Code 128. With a straightforward approach, the BarcodeReader.Read
method is employed to read barcodes from images, passing the image and options as arguments. This method simplifies a complex task into a single line of code. The results are processed using a for
loop to print each barcode's information, showcasing the effectiveness of Iron Barcode in displaying multiple barcodes' data. This process is especially beneficial for applications such as automating data entry and tracking products. The tutorial encourages further exploration of Iron Barcode for additional functionalities and invites viewers to subscribe for more tutorials. For those eager to start, a link to a free trial of Iron Barcode is provided, offering a firsthand experience of its capabilities.
Here is a sample code illustrating the process:
// Import the necessary namespace from the Iron Barcode library
using IronBarCode;
using System;
class BarcodeReaderExample
{
static void Main()
{
// Load a barcode image from a file path
var barcodeImage = BarcodeReader.Read("path/to/barcode/image.png", new BarcodeReaderOptions()
{
// This option allows the reading of multiple barcodes in a single image
AcceptMultipleBarcodes = true
});
// Loop through each barcode result and print its value and type
foreach (var barcode in barcodeImage)
{
Console.WriteLine($"Barcode Value: {barcode.Value}, Barcode Type: {barcode.Type}");
}
}
}
// Import the necessary namespace from the Iron Barcode library
using IronBarCode;
using System;
class BarcodeReaderExample
{
static void Main()
{
// Load a barcode image from a file path
var barcodeImage = BarcodeReader.Read("path/to/barcode/image.png", new BarcodeReaderOptions()
{
// This option allows the reading of multiple barcodes in a single image
AcceptMultipleBarcodes = true
});
// Loop through each barcode result and print its value and type
foreach (var barcode in barcodeImage)
{
Console.WriteLine($"Barcode Value: {barcode.Value}, Barcode Type: {barcode.Type}");
}
}
}
' Import the necessary namespace from the Iron Barcode library
Imports IronBarCode
Imports System
Friend Class BarcodeReaderExample
Shared Sub Main()
' Load a barcode image from a file path
Dim barcodeImage = BarcodeReader.Read("path/to/barcode/image.png", New BarcodeReaderOptions() With {.AcceptMultipleBarcodes = True})
' Loop through each barcode result and print its value and type
For Each barcode In barcodeImage
Console.WriteLine($"Barcode Value: {barcode.Value}, Barcode Type: {barcode.Type}")
Next barcode
End Sub
End Class
Explanation of the Code:
Using Directives: The using
directive is used to import the necessary namespaces, including IronBarCode
for accessing the barcode reading functionalities, and System
for basic I/O operations.
Reading Barcodes: The BarcodeReader.Read
method is called with two parameters: the file path to the image and BarcodeReaderOptions
where AcceptMultipleBarcodes
is set to true
. This enables the reading of multiple barcodes from a single image.
foreach
loop is used to iterate over the collection of barcode results. For each barcode, its value and type are printed to the console, demonstrating the library's capability to handle multiple barcodes efficiently.Further Reading: How to Read Multiple Barcodes at Once