如何使用 C# 读取条形码

这个简单的操作方法主题说明了如何使用 C#** **Read Barcode。为了读取条形码,可以使用简单的 API 调用和少量编码步骤来开发基于 C# 的应用程序。您可以在 Windows、macOS 和 Linux 操作系统中运行的任何 .NET 支持的应用程序中使用该示例,而无需依赖任何第三方工具或其他 API。

使用 C# 读取条形码的步骤

  1. 包括来自 NuGet 包管理器的 Aspose.BarCode for .NET
  2. 包括对 Aspose.Barcode 和 Aspose.BarCode.BarCodeRecognition 命名空间的引用
  3. 创建 BarCodeReader class 的对象并加载条形码图像文件
  4. 使用 BarCodeReader 的 DecodeType 枚举器设置条形码类型
  5. 遍历提取的条形码信息以供进一步使用

C# 中的上述步骤只需几行代码即可从图像中读取条形码。该过程将从使用 NuGet 添加包括 API 并包括所需的命名空间开始。然后我们将使用 BarCodeReader 实例读取包含单个或多个条形码的源 PNG 文件。我们还将使用 DecodeType 枚举器设置我们有兴趣阅读的所需条形码类型。在随后的几行中,条形码阅读器将从图像中提取信息,我们将对其进行迭代以便在我们的应用程序中进一步使用。

使用 C# 读取条形码的代码

using System;
using Aspose.BarCode;
using Aspose.BarCode.BarCodeRecognition;
namespace KBBarcode
{
public class ReadBarcode
{
public static void BarcodeReader()
{
// Applying product license to read the Barcodes from image
License BarcodeLic = new License();
BarcodeLic.SetLicense("Aspose.Total.lic");
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($"{codeResult.CodeTypeName}:{codeResult.CodeText}");
}
}
}
}

在上面的示例中,为了创建一个条形码阅读器,C# 源代码 用于少数 API 调用。 API 支持从 DecodeType 枚举器中指定的各种条形码类型读取信息。只需几行代码就可以在 C# 中开发条码扫描仪

在本主题中,我们探讨了 C# 中的应用程序如何轻松地从 PNG 图像中扫描条形码。如果您对生成 QR 码感兴趣,请参阅有关如何 在 C# 中生成二维码 的文章。

 简体中文