1D Barcode Reader for .NET
Getting Started with 1D Barcode Reader for .NET
The Aspose.BarCode 1D Reader for .NET is a powerful and efficient API designed for developers to read and decode a wide range of 1D barcodes from images within their .NET applications. This guide provides a complete overview of the API’s features and capabilities, with practical C# code examples to help you integrate it quickly and effectively.
Supported 1D Barcode Symbologies
Our 1D barcode reader supports all major linear barcode types, allowing you to handle a variety of business needs. You can specify one or multiple symbologies per decoding session to improve both accuracy and performance.
The following barcode symbologies are supported:
- UPC-A
- UPC-E
- EAN-13
- EAN-8
- Code 39
- Code 93
- Code 128
- Interleaved 2 of 5
- Code 11
Here is an example of how to specify a symbology to read using the BarcodeReader
class:
// Create a new instance of BarcodeReader, specifying Code39
using (Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader("image.png", Aspose.BarCode.Generation.DecodeType.Code39))
{
// Read the barcode
var result = reader.ReadBarCodes()[0];
Console.WriteLine("Decoded Barcode: " + result.CodeText);
}
Reading and Decoding 1D Barcodes from Images
The BarcodeReader
class is the central component for reading barcodes. It can handle image files, streams, or in-memory bitmaps, providing seamless integration with various data sources like scanners, cameras, or file-based workflows.
Reading from a File Path
The simplest way to read a barcode is by providing the image file path:
// Read from an image file
using (Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader("image.png"))
{
foreach (var result in reader.ReadBarCodes())
{
Console.WriteLine($"Found Code: {result.CodeText}, Type: {result.CodeType}");
}
}
Reading from an Image Stream
For applications handling images from memory or network sources, you can use a stream:
// Read from a stream
using (System.IO.Stream stream = System.IO.File.OpenRead("image.png"))
{
using (Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader(stream))
{
foreach (var result in reader.ReadBarCodes())
{
Console.WriteLine($"Found Code: {result.CodeText}, Type: {result.CodeType}");
}
}
}
Accessing Decoded Barcode Data
Each decoded barcode returns a BarCodeResult
object, which provides rich metadata, including the decoded text, symbology type, and bounding box coordinates.
// Get decoded information
using (Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader("image.png"))
{
var result = reader.ReadBarCodes()[0];
// Get the symbology and code text
string symbology = result.CodeType.ToString();
string codeText = result.CodeText;
Console.WriteLine($"Symbology: {symbology}, Code Text: {codeText}");
}
Advanced Features & Optimization
Beyond basic reading, the 1D Barcode Reader offers powerful features to improve accuracy and performance in complex scenarios.
- Rotation and Skew Compensation: Our API automatically detects and corrects for rotation and perspective distortion. Barcodes captured at odd angles are read reliably without any pre-processing.
- Custom Region of Interest (ROI): Restrict the scanning to a specific rectangular area within an image. This dramatically accelerates decoding when you know the barcode’s location and reduces false positives.
- Batch and Parallel Processing: For high-volume services, the library supports parallel decoding across multiple images or threads.
- Error Detection and Correction: The reader leverages built-in checksum and error-correction mechanisms where supported, flagging invalid barcodes and providing confidence scores for each read.
Example: Handling Errors Gracefully
It’s crucial to implement error handling to manage scenarios where a barcode is unreadable or not found.
try
{
using (Aspose.BarCode.BarCodeRecognition.BarCodeReader reader = new Aspose.BarCode.BarCodeRecognition.BarCodeReader("damaged_image.png"))
{
if (reader.ReadBarCodes().Length > 0)
{
var result = reader.ReadBarCodes()[0];
Console.WriteLine($"Successfully read barcode: {result.CodeText}");
}
else
{
Console.WriteLine("No barcode found in the image.");
}
}
}
catch (Aspose.BarCode.BarCodeRecognition.BarCodeException ex)
{
Console.WriteLine("Error reading barcode: " + ex.Message);
}
Installation and Setup
Getting started with the Aspose.BarCode 1D Reader is simple. Just add the package to your project.
- Install via NuGet: Add the
Aspose.BarCode
package to your project using the NuGet Package Manager. - Licensing: For production use, configure metered licensing as described in the Metered Licensing guide .
By following this guide, you can build robust and scalable solutions for extracting 1D barcode data from virtually any image source using the Aspose.BarCode 1D Reader for .NET.