How to Read Multiple Barcodes at Once in C#

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
$vbLabelText   $csharpLabel

Explanation of the Code:

  1. 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.

  2. 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.

  3. Iterating Over Results: A 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

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he says it’s one of his favorite aspects of working with Iron Software. Jordi grew up in Miami, Florida and studied Computer Science and Statistics at University of Florida.
< PREVIOUS
How to Generate Barcode Images in C# for .NET using Iron Barcode
NEXT >
How to Read Barcodes From System Drawing Objects