1D Barcode Reader for .NET

Introduction to 1D Barcode Reader for .NET

The 1D Barcode Reader for .NET is a powerful plugin that allows developers to read and decode 1D barcodes from images. This guide will walk you through the features and capabilities of the plugin, providing code examples in C# to help you get started.

Supported Barcode Symbologies

The 1D Barcode Reader for .NET supports a wide range of 1D barcode symbologies, including:

  • UPC-A
  • UPC-E
  • EAN-13
  • EAN-8
  • Code 39
  • Code 93
  • Code 128
  • Interleaved 2 of 5
  • Code 11

You can specify the symbology to read using the BarcodeReader class:

// Create a new instance of BarcodeReader
Aspose.BarCode.BarcodeReader reader = new Aspose.BarCode.BarcodeReader("image.png", Aspose.BarCode DecodeType.Code39);

// Read the barcode
Aspose.BarCode.Result result = reader.ReadBarCodes()[0];

Reading Barcodes from Images

To read a barcode from an image, you can use the BarcodeReader class and specify the image file path or stream:

// Create a new instance of BarcodeReader
Aspose.BarCode.BarcodeReader reader = new Aspose.BarCode.BarcodeReader("image.png");

// Read the barcode
Aspose.BarCode.Result result = reader.ReadBarCodes()[0];

You can also read barcodes from streams:

// Create a new instance of BarcodeReader
using (System.IO.Stream stream = System.IO.File.OpenRead("image.png"))
{
    Aspose.BarCode.BarcodeReader reader = new Aspose.BarCode.BarcodeReader(stream);
    // Read the barcode
    Aspose.BarCode.Result result = reader.ReadBarCodes()[0];
}

Decoding Barcodes

The BarcodeReader class returns a Result object, which contains information about the decoded barcode, including the symbology, code text, and supplement:

// Create a new instance of BarcodeReader
Aspose.BarCode.BarcodeReader reader = new Aspose.BarCode.BarcodeReader("image.png");

// Read the barcode
Aspose.BarCode.Result result = reader.ReadBarCodes()[0];

// Get the symbology
string symbology = result.CodeType;

// Get the code text
string codeText = result.CodeText;

Error Handling

The 1D Barcode Reader for .NET throws exceptions if an error occurs during barcode reading or decoding:

try
{
    // Create a new instance of BarcodeReader
    Aspose.BarCode.BarcodeReader reader = new Aspose.BarCode.BarcodeReader("image.png");

    // Read the barcode
    Aspose.BarCode.Result result = reader.ReadBarCodes()[0];
}
catch (Aspose.BarCode.BarcodeException ex)
{
    Console.WriteLine("Error reading barcode: " + ex.Message);
}
 English