Set Target Barcode Types for Recognition

Overview

Aspose.BarCode for .NET supports more than 60 barcode types for recognition. To minimize the time required to complete recognition and avoid attempts to recognize outdated barcodes that are still used as a legacy of some industrial systems, it is recommended to select target barcode symbologies that will be considered for recognition. However, in the case when there is no information about precise symbologies that can be presented in a source image, it is possible to assign DecodeType.AllSupportedTypes to the BarCodeReadType property so that the source image will be checked for the presence of all supported barcode types. This setting results in the increased time required to complete barcode recognition.

List Barcode Types Defined in DecodeType

Target symbologies for barcode recognition can be specified as a list and passed to the BarCodeReader constructor or assigned to the BarCodeReadType property.

The following code snippet demonstrates how to set target symbologies (Code 39, Code 128, and RM4SCC) using DecodeType.

using (BarCodeReader reader = new BarCodeReader($"{path}multiple_codes.png",
    DecodeType.Code39Extended, DecodeType.Code128, DecodeType.RM4SCC))
{
    Console.WriteLine("ReadDecodeTypeList:");
    foreach (BarCodeResult result in reader.ReadBarCodes())
        Console.WriteLine($"{result.CodeTypeName}:{result.CodeText}");
}

MultiDecodeType Mode

The other way to set target symbologies for recognition is to list the required barcode types in a constructor of class MultiDecodeType and then to pass an instance of this class to the BarCodeReader constructor or assign it to the BarCodeReadType property.

The following code sample explains how to define target symbologies for barcode reading (in this case, Code 39, Code 128, and RM4SCC) through MultiDecodeType.

using (BarCodeReader reader = new BarCodeReader($"{path}multiple_codes.png"))
{
    reader.BarCodeReadType = new MultiDecodeType(DecodeType.Code39Extended, DecodeType.Code128, DecodeType.RM4SCC);
    Console.WriteLine("ReadMultiDecodeType:");
    foreach (BarCodeResult result in reader.ReadBarCodes())
        Console.WriteLine($"{result.CodeTypeName}:{result.CodeText}");
}

Predefined Sets of Types

Class DecodeType contains various predefined sets of symbologies for recognition, including the following ones:

  • AllSupportedTypes - all supported barcode types
  • Types1D - all supported 1D symbologies
  • Types2D - all supported 2D symbologies
  • PostalTypes - all supported postal symbologies that are mainly used by postal services
  • MostCommonTypes - a set of most widely used barcode standards defined according to the Aspose recommendations

The required symbology set can be defined in the BarCodeReader constructor or assigned to the BarCodeReadType property.

The following code snippet illustrates how to specify target barcode types using the predefined set called Types2D.

using (BarCodeReader reader = new BarCodeReader($"{path}multiple_codes.png", DecodeType.Types2D))
{
    Console.WriteLine("ReadTypes2D:");
    foreach (BarCodeResult result in reader.ReadBarCodes())
        Console.WriteLine($"{result.CodeTypeName}:{result.CodeText}");
}