NET 的 1D 条码阅读器
開始使用 1D Barcode Reader 為 .NET
Aspose.BarCode 1D Reader for .NET 是一个强大而高效的 API,旨在让开发人员从他们的 .NET 应用程序中的图像中阅读和编码大量的 1D 条形码. 本指南提供了 API 的功能和功能的完整概述,提供实用的 C# 代码示例,以帮助您快速有效地集成.
支持 1D 条形码符号
我们的 1D 条形码阅读器 支持所有主要的线条条码类型,允许您处理各种业务需求.
支持下列 条码符号:
- UPC-A
- 此分類上一篇: UPC-E
- 此分類上一篇: EAN-13
- 伊安8
- 代码 39
- 代码 93
- 代码 128
- 交付 2 的 5
- 代码 11
下面是如何指定一个符号来阅读的例子 BarcodeReader
班级:
// 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);
}
从图像中阅读和解码1D条形码
是的 BarcodeReader
它可以处理图像文件、流或内存比特地图,提供无缝的集成与各种数据来源如扫描仪、摄像机或基于文件的工作流.
从文件路径阅读
阅读条形码的最简单方法是通过提供图像文件路径:
// 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}");
}
}
从图像流中阅读
对于应用程序从内存或网络来源处理图像,您可以使用流:
// 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}");
}
}
}
获取解密条形码数据
每个解码的条形码都会返回一个 BarCodeResult
对象,提供丰富的金属数据,包括解码文本,符号类型和边缘框坐标.
// 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}");
}
先进功能与优化
除了基本阅读之外, 1D Barcode Reader 还提供了强大的功能,以提高复杂场景的准确性和性能.
- 旋转和折叠补偿 :我们的API会自动检测和纠正曲折和视野扭曲.
- 自定义利益区(ROI) :将扫描限制在图像内部的特定直角区域,这在您知道条码的位置时显著加速解码,并减少虚假积极.
- Batch and Parallel Processing :对于高容量服务,图书馆支持通过多个图像或线条进行平行解码.
- 错误检测和纠正:读者在支持的内置检查和误解机制中使用,标记不合格的条码,并为每个阅读提供信任分数.
例子:处理错误是善良的
实施错误处理至关重要,以管理条形码不可读或未找到的场景.
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);
}
安装和设置
開始使用 Aspose.BarCode 1D Reader 是簡單的.
- 通过 NuGet 安装 : 添加
Aspose.BarCode
使用 NuGet Package Manager 将包装到您的项目. - 许可证 :用于生产用途,如下文所描述设置 测量授权 测量许可指南 .
通过遵循此指南,您可以使用 Aspose.BarCode 1D Reader for .NET 从几乎任何图像来源中提取 1D 条形码数据 的可扩展性解决方案.