IRONSOFTWAREHOME

如何使用 IronBarcode 调整 C# 的阅读速度

Curtis Chau
Curtis Chau
Updated: 2026年4月22日

IronBarcode 提供四种读取速度选项(ExtremeDetail),让您在使用 C# 读取条码时能够在处理速度和准确性之间进行权衡,其中 Balanced 是大多数应用程序的推荐起点。

简介

在读取大量条形码时,准确性至关重要,但资源分配和处理效率也是同样重要的考虑因素。 输入图像的质量决定了条形码阅读器应如何处理这些图像--是跳过清晰图像的预处理,还是使用更耗费资源的选项来提高降级条形码的准确性。

IronBarcode 可灵活选择处理速度和准确度级别,让您控制条码读取过程的方方面面。 您可以根据输入的图像和可用资源做出决定。 如需了解更高级的条形码读取场景,请浏览我们的综合条形码读取教程,其中涵盖了各种格式和技术。

本文提供了针对不同情况选择最佳阅读速度的指南。 我们将使用二维码样本来演示改变阅读速度对结果的影响。 如果您要专门处理 QR 代码,请查看我们的 C# QR 代码生成器教程,以创建测试样本。

快速入门:以平衡的速度读取BarCode using IronBarcode 的 BarcodeReaderOptions 可立即设置扫描的 Speed 级别。 此示例展示了如何使用 Balanced 设置快速读取条码以获得快速而可靠的结果。

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2复制并运行这段代码。

    var results = IronBarCode.BarcodeReader.Read("path/to/image.png", new IronBarCode.BarcodeReaderOptions { Speed = IronBarCode.ReadingSpeed.Balanced });
    C#
  3. 3部署到您的生产环境中进行测试

    通过免费试用立即在您的项目中开始使用IronBarcode
    arrow pointer

有哪些不同的阅读速度选项?

IronBarcode 提供四种 ReadingSpeed 选项:DetailedExtremeDetail。 我们将使用一个包含大部分降级条形码图像和一些清晰图像的样本集来检查每个选项,以展示库的功能。 有关支持格式的完整列表,请访问我们的支持的条形码格式页面

我们将使用 .NET 基准库来测量处理时间和内存使用情况,展示每种选项的比较情况,并确定每种阅读速度的理想场景。 我们将演示基准代码和计算成功读取降级条形码的直接方法。 有关配置阅读器选项的更多详情,请参阅我们的条码阅读器设置示例

何时应使用更快的速度选项?

Faster 选项提供了最快的条码读取速度且资源消耗最小,但会降低准确性。 该流程跳过了图像预处理,在输入图像已经清晰锐利的情况下效果最佳。

此示例将 Speed 属性设置为 ReadingSpeed.Faster,导入一目录条码,打印找到的条码及其值、类型,以及每个图像的计数。 要更好地理解从各种图像格式中读取条形码,请查看我们的从图像中读取条形码指南。

using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Faster
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"Faster could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");

Faster 选项在25秒内从430个中检测到146个条码结果,达成了33.95% 的准确率。 这种方法虽然速度快,但只适合原始图像条件。 在处理单个图像中的多个条形码时,请考虑我们的读取多个条形码指南,以获得最佳配置。

为什么平衡是推荐的速度选项?

Balanced 选项在准确性和读取性能之间取得了平衡。 IronBarcode 采用轻图像处理技术,使条形码区域清晰,更易于检测和读取。 对于大多数现代图像,建议使用此设置,因为轻度处理通常能产生准确的结果。

让我们使用相同的图像来演示 Balanced 如何影响输出结果。 关于异步操作,请浏览我们的 async 和多线程与 IronBarcode 指南。

using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"Balanced could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");

Balanced 选项在43秒内从430个中检测到237个条码结果。 它提供了55.11% 的准确率——相较于 Faster 有显著的提升——而时间仅增加了一点。 此选项在内存和速度之间保持有效的平衡,使其成为大多数情况下的理想选择和推荐起点。 这种平衡的方法与适当的图像预处理技术配合使用效果尤佳。

何时需要详细速度选项?

当图像严重模糊或失真且 Balanced 无法产生清晰结果时,使用 Detailed 选项。 它应用了中等预处理,以明确条形码区域并减少数字噪声,从而更好地进行检测。 对于严重降级的图像,请查阅我们的图像校正指南,其中涵盖了各种预处理技术。

让我们应用 Detailed 设置,观察其对输出的影响。

using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Detailed
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"Detailed could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");

Detailed 选项在5分30秒内从430个中检测到237个条码结果。 其在严重降级的 BarCode 上 55.11% 的成功率证明了其准确性。 不过,由于处理时间大大增加,因此这一方案应专门用于降级的 BarCode 图像。 在处理不完全条形码时,请查阅我们的不完全条形码处理示例,了解更多策略。

哪些情况需要极高的细节速度?

ExtremeDetail 设置对条码图像进行了大量处理,显著降低了读取性能。 这种 CPU 密集型选项最适合扫描一个输入文件中多个不清晰或模糊的 BarCode。当其他选项无法产生预期结果时,请将其作为最后手段使用。 对于大批量处理场景,可探索 从 PDF 文件中读取条形码,这些文件通常每页包含多个条形码。

让我们应用 ExtremeDetail 设置,观察其影响。

using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

var optionsFaster = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.ExtremeDetail
};

// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";

// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");

int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
    // Read the barcode
    var results = BarcodeReader.Read(file, optionsFaster);

    if (results.Any())
    {
        Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
        foreach (var result in results)
        {
            Console.WriteLine($"  Value: {result.Value}, Type: {result.BarcodeType}");
            countFaster++;
        }
    }
    else
    {
        Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
    }
}

stopwatch.Stop();

// Print number of images the barcode reader could decode
Console.WriteLine($"ExtremeDetail could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");

ExtremeDetail 选项在大约10分钟内识别出430个条码图像中的313个。 虽然在严重降级的 BarCode 上实现了令人印象深刻的 72.79% 的准确率,但其高资源消耗使其只适合作为最后的手段。 使用此选项前,请考虑对图像进行预处理。

如何比较不同的速度?

模式找到条形码平均时间每份文件所需时间GC压力精度提升
更快147/430(33.95%)25秒0.058秒高(第二代:177K)Baseline
平衡237/430(55.11%)43秒0.1秒高(第二代:151K)+62.32% 对比 Faster
详细237/430(55.11%)5.50分钟0.767秒非常高(第二代:297K)+0% vs 平衡
极致细节313/430(72.79%)10.14分钟1.414秒Extreme(第二代:474万)Detailed 相比 +32.08

如何为我的应用程序选择合适的速度?

根据上述比较,先从 Faster 设置入手,再逐步通过 DetailedExtremeDetail 来识别显著的输出差异。 对于大多数场景,Balanced 足以应对所有情况。 仅对严重失真的图像使用 DetailedExtremeDetail。 对于薄或低质量的条码,可以将速度设置与 MinScanLines = 1 结合使用,以提高检测灵敏度。

虽然 DetailedExtremeDetail 采用了中等和大量处理,但有时分开流程更为有效——在条码读取之前先手动应用图像过滤而不是使用单一流程。 有关图像预处理的更多信息,请参阅本指南

哪种速度设置符合我的使用案例?

根据图像质量选择采样速度的决策树,从更快到更详细+极详细选项

常见问题解答

有哪四种条形码读取速度可供选择?

IronBarcode 提供四种 ReadingSpeed 选项:更快、均衡、详细和极致详细。每个选项都在处理速度和准确性之间提供了不同的平衡,平衡是大多数应用程序的推荐起点。

扫描 BarCode 时如何设置读取速度?

您可以使用 IronBarcode 中的 BarcodeReaderOptions 类设置读取速度。只需创建一个新的 BarcodeReaderOptions 对象,并将 Speed 属性设置为所需的 ReadingSpeed 值(Faster、Balanced、Detailed 或 ExtremeDetail),然后将其传递给 Read 方法。

我应该为我的应用程序选择哪种阅读速度?

IronBarcode 建议大多数应用从平衡速度设置开始。如果您拥有高质量、清晰的条码图像,则可以使用 "更快 "模式。对于质量下降或较差的图像,可考虑使用 "详细 "或 "极详细 "模式,以获得更高的准确性。

不同阅读速度选项之间的权衡是什么?

IronBarcode 读取速度的权衡在于处理速度和准确性之间。更快模式能快速处理图像,但可能会漏掉质量较差图像中的条形码。ExtremeDetail 模式提供最高的准确性,但需要更多的处理时间和内存资源。

我可以用不同的速度设置读取多种条形码格式吗?

是的,IronBarcode 支持读取各种条码格式,包括所有速度设置下的 QR 码。速度设置会影响处理方式,但不会限制您可以读取的条码类型。请访问支持的条码格式页面以获取完整列表。

图像质量如何影响我应该选择的阅读速度?

图像质量直接影响您在 IronBarcode 中的速度选择。清晰、高质量的条码图像可通过 "更快 "模式进行高效处理。退化、模糊或对比度低的图像则需要使用 "详细 "或 "极详细 "模式,以确保条码检测和读取的准确性。

读取有速度选项的 BarCode 的最基本工作流程是什么?

IronBarcode 的最低工作流程包括 5 个步骤:1)下载 C# 库;2)使用 BarcodeReaderOptions 设置读取速度;3)使用图像路径调用读取方法;4)提取并打印条码值;5)评估不同速度之间的性能权衡。

如何衡量不同阅读速度对性能的影响?

IronBarcode 在不同读取速度下的性能可以使用 .NET 基准库进行测量,以跟踪处理时间和内存使用情况。这有助于您根据具体使用情况和资源限制确定最佳速度设置。

What is the impact of applying heavy processing in the ExtremeDetail setting?

The ExtremeDetail setting significantly lowers reading performance and increases CPU usage due to intensive image preprocessing. It can recover certain barcodes more effectively than other settings, particularly in highly degraded images.

Which barcode reading speed setting should I use for high-volume processing?

For high-volume processing with clear, high-quality images, the Faster setting is optimal due to its speed and low resource consumption. However, it's important to test it against your specific data set to ensure it meets your needs.

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

...
阅读更多

准备开始了吗?

Nuget Downloads 2,422,100版本:2026.9刚刚发布

立即获取您的免费30 天试用密钥
无需信用卡或创建账户
C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索 "IronBarcode"
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

  1. 下载并将 IronBarCode 解压到解决方案目录中的 ~/Libs 等位置
  2. 在 Visual Studio 解决方案资源管理器中,右键单击引用。选择浏览,"IronBarcode.dll"

许可 $999

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户