阅读条形码在许多应用程序中是常见的要求,如库存管理和门票验证. 此教程展示了如何使用 C# 与 Aspose.BarCode 为 .NET 读字符码。

引入

本指南提供使用 C# 阅读条形码的步骤指示,通过遵循下面列出的步伐,您可以开发一个强大的字符码阅读器应用程序,支持多种字体代码类型。

阅读条形码的好处

  • 效率:在数字格式快速获取加密信息。
  • 多元性:可集成到各种应用程序,包括库存管理和门票验证。
  • 易于使用:通过快速扫描简化数据输入过程。

原标题:准备环境

  • 设置 Visual Studio 或任何兼容的 .NET IDE。
  • 在 NuGet Package Manager 中安装 Aspose.BarCode。
Install-Package Aspose.BarCode

步骤指南阅读条形码

步骤1:包含必要的名称空间

在您的代码中添加所需的名称空间的参考。

using Aspose.BarCode;
using Aspose.BarCode.BarCodeRecognition;

步骤2:下载条码图像

创建一个例子 BarCodeReader 分类并加载条码图像文件。

using (BarCodeReader barcodeReader = new BarCodeReader("multiple_codes.png", DecodeType.Pdf417, DecodeType.DataMatrix, DecodeType.QR, DecodeType.Code39Extended, DecodeType.Code128, DecodeType.RM4SCC))
{
    // Further processing follows here
}

步骤3:设置条形码类型

指定您想要阅读的条形码类型 DecodeType 列表。

barcodeReader = new BarCodeReader("multiple_codes.png", DecodeType.Pdf417, DecodeType.DataMatrix, DecodeType.QR, DecodeType.Code39Extended, DecodeType.Code128, DecodeType.RM4SCC);

步骤4:通过结果

提取条码信息并将其打印到控制台。

foreach (BarCodeResult codeResult in barcodeReader.ReadBarCodes())
{
    Console.WriteLine("{0}: {1}", codeResult.CodeTypeName, codeResult.CodeText);
}

完整的代码示例阅读条形码

下面是一个完整的例子,表明如何从图像中阅读条形码:

using (BarCodeReader barcodeReader = new BarCodeReader("multiple_codes.png", DecodeType.Pdf417, DecodeType.DataMatrix, DecodeType.QR, DecodeType.Code39Extended, DecodeType.Code128, DecodeType.RM4SCC))
{
    Console.WriteLine("ReadSimpleExample:");
    foreach (BarCodeResult codeResult in barcodeReader.ReadBarCodes())
    {
        Console.WriteLine("{0}: {1}", codeResult.CodeTypeName, codeResult.CodeText);
    }
}

更多信息

  • Aspose.BarCode 图书馆支持各种条码格式,允许您轻松阅读多种类型的代码。
  • 考虑实施缺乏或不可读的条形码的场景的额外错误处理。

结论

此教程引导您通过使用 Aspose.BarCode 在 C# 中阅读条形码的过程. 只有几个条形码,您可以有效地从条形码图像中提取信息. 对于额外的条形码生成和操作功能,请参阅更多关于 Aspose 产品可用的教程和指南。

More in this category