2D Barcode Reader for .NET
Introduction to 2D Barcode Reader for .NET
The 2D Barcode Reader for .NET is a plugin that enables developers to read 2D barcodes from images. This guide provides an overview of the available features and explains how to perform common tasks using code examples in .NET.
Supported Barcode Types
The 2D Barcode Reader for .NET supports the following 2D barcode types:
- QR Code
- Data Matrix
- PDF417
- Aztec
Reading Barcodes from Images
To read a barcode from an image, you can use the BarCodeReader
class. Here is an example of how to do this in C#:
using (BarCodeReader reader = new BarCodeReader("image.png"))
{
foreach (BarCodeResult result in reader.ReadBarCodes())
{
Console.WriteLine("Code Text: " + result.CodeText);
Console.WriteLine("Symbology: " + result.CodeType);
}
}
Customizing the Reading Process
You can customize the reading process by setting various options, such as image quality, and more. Here is an example of how to do this in C#:
using (BarCodeReader reader = new BarCodeReader("image.png"))
{
reader.QualitySettings = QualitySettings.HighQuality;
foreach (BarCodeResult result in reader.ReadBarCodes())
{
Console.WriteLine("Code Text: " + result.CodeText);
Console.WriteLine("Symbology: " + result.CodeType);
}
}
Handling Errors and Exceptions
The 2D Barcode Reader for .NET throws exceptions when errors occur during the reading process. You can handle these exceptions using try-catch blocks. Here is an example of how to do this in C#:
try
{
using (BarCodeReader reader = new BarCodeReader("image.png"))
{
foreach (BarCodeResult result in reader.ReadBarCodes())
{
Console.WriteLine("Code Text: " + result.CodeText);
Console.WriteLine("Symbology: " + result.CodeType);
}
}
}
catch (BarCodeRecognitionException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
Best Practices and Performance Optimization
To optimize performance, it is recommended to use high-quality images and to set the QualitySettings
property to HighPerformance
. Additionally, you can improve performance by using multi-threading or parallel processing. Here is an example of how to do this in C#:
BarCodeReader.ProcessorSettings.UseAllCores = true;
Parallel.ForEach(Files.GetFiles("images"), file =>
{
using (BarCodeReader reader = new BarCodeReader(file))
{
reader.QualitySettings = QualitySettings.HighPerformance;
foreach (BarCodeResult result in reader.ReadBarCodes())
{
Console.WriteLine("Code Text: " + result.CodeText);
Console.WriteLine("Symbology: " + result.CodeType);
}
}
});