IronBarcode 操作指南 读取速度选项 如何使用 IronBarcode 在 C# 中调整读取速度 Curtis Chau 已更新:十月 12, 2025 下载 IronBarcode NuGet 下载 DLL 下载 免费试用 法学硕士副本 法学硕士副本 将页面复制为 Markdown 格式,用于 LLMs 在 ChatGPT 中打开 向 ChatGPT 咨询此页面 在双子座打开 向 Gemini 询问此页面 在双子座打开 向 Gemini 询问此页面 打开困惑 向 Perplexity 询问有关此页面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 复制链接 电子邮件文章 This article was translated from English: Does it need improvement? Translated View the article in English 准确性对于可扩展性和读取大量条形码至关重要,但条形码阅读器如何分配资源以及其效率如何也必须考虑在内。 根据输入图像和图像本身的质量,开发人员必须决定条形码阅读器应该如何处理和读取图像,例如,如果图像清晰,是否跳过图像预处理;或者采用资源密集型选项来提高条形码阅读器的读取精度。 IronBarCode 让您可以灵活地选择条形码处理的速度和精度,从而可以微调和控制流程的各个方面。 您可以根据您拥有的输入图像和您想要分配的资源来做出决定。 下面的文章将提供一份关于如何选择最佳阅读速度的一般性指导原则。 我们将使用一组二维码样本来简要说明改变读取速度会如何影响结果。 快速入门:以均衡速度读取条形码 使用 IronBarcode 的BarcodeReaderOptions可以立即设置扫描Speed级别。 此示例展示了开发人员如何使用Balanced设置快速读取条形码,从而获得快速可靠的结果。 立即开始使用 NuGet 创建 PDF 文件: 使用 NuGet 包管理器安装 IronBarcode PM > Install-Package BarCode 复制并运行这段代码。 var results = IronBarCode.BarcodeReader.Read("path/to/image.png", new IronBarCode.BarcodeReaderOptions { Speed = IronBarCode.ReadingSpeed.Balanced }); 部署到您的生产环境中进行测试 立即开始在您的项目中使用 IronBarcode,免费试用! 免费试用30天 最小工作流程(5 个步骤) 下载 C# 库以调整阅读速度 使用BarcodeReaderOptions类设置读取速度 使用Read方法从各种图像格式中提取条形码值 打印出条形码的值 评估不同阅读速度之间的性能权衡 阅读速度 在 IronBarCode 中,开发者可以将ReadingSpeed设置为四个不同的选项: Faster 、 Balanced 、 Detailed和ExtremeDetail 。 我们将逐一介绍这些选项,并通过一个示例集作为基准,来了解ReadingSpeed值如何影响流程的输出。 样本集包含一些质量较差的条形码图像和一些质量较差的图像,其中质量较差的图像占比较大,以说明该库的功能。 我们还将使用流行的 .NET 基准测试库来测试时间和内存使用情况,说明每种选项与其他选项的比较情况,并确定每种阅读速度选项的理想场景和情况。 我们将展示用于使用该库进行基准测试的代码,以及一种更直接的方法来推断 IronBarCode 可以读取多少降级条形码。 更快的速度选项 第一个值是Faster 。 一般来说,将Speed属性设置为此值可以以最少的资源实现最快的条形码读取速度,但代价是精度降低。 该过程会跳过图像预处理,如果图像本身在输入到该过程之前已经清晰锐利,则通常建议采用此方法。 在这个例子中,我们将Speed属性设置为ReadingSpeed.Faster ,导入了包含所有条形码的目录,并打印出找到的所有条形码,以及它们的值、类型和从每张图像中找到的条形码数量。 :path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-faster.cs 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"); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel Faster在 25 秒内检测出 430 个条形码结果中的 146 个。 此选项速度很快,可以解码条形码的约 33.95%。 虽然速度很快,但这种方法通常只适用于图像质量完美无瑕的情况。 平衡速度选项 Balanced值兼顾了准确性和读取性能。 应用此设置时,IronBarcode 会对图像进行轻微处理,以清晰显示条形码区域,使其更易于条形码读取器检测和读取。 一般来说,对于大多数现代图像来说,这是推荐的设置,因为轻微的处理应该足以产生准确的结果。 让我们使用相同的图像,并展示Balanced值如何影响输出结果。 :path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-balanced.cs 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"); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel Balanced在 43 秒内检测出 430 个条形码结果中的 237 个。 与Faster选项相比,"平衡"选项的准确率提高了 55.11%,而耗时仅略有增加。 Balanced选项在内存和速度之间保持了高效的平衡,使其成为大多数情况下的理想选择,也是推荐的初始设置。 详细速度选项 在图像严重模糊或扭曲,以及Balanced选项无法清晰检测和产生结果的情况下,开发人员可以选择使用Detailed属性对图像应用中等程度的预处理,以进一步清晰地显示条形码区域,并清除更多数字噪声,以便条形码读取器能够检测到条形码。 这次我们将Detailed设置应用于Speed属性,看看它是否会影响图像的整体输出。 :path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-detailed.cs 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"); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel Detailed检测在 5 分 30 秒内检测到 430 个条形码中的 237 个结果。 在严重劣化的条形码数据集上,其成功率达到 55.11%,这证明了其准确性。 然而,这种权衡是显著的,因为处理时间会大幅增加。 因此,此选项必须专门用于条形码图像质量下降的情况。 极致细节速度选项 Speed属性的最后一个设置是ExtremeDetail ,它会对条形码图像进行大量处理,以便读取器可以读取它,这通常会降低 IronBarcode 的读取性能。 此选项非常适合扫描单个输入文件中大量条形码,尤其适用于批量扫描不清晰或模糊的条形码。 该操作会占用大量 CPU 资源,应在其他方法均无法达到预期效果时作为最后的选择。 让我们将ExtremeDetail设置应用到Speed属性,看看是否会影响结果。 :path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-extreme-detailed.cs 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"); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel ExtremeDetail选项能够识别 430 个条形码图像中的 313 个,每次运行平均需要 10 分钟。 它功能强大,但由于资源消耗量高,因此只适合作为严重退化选项的最后手段。 即使在严重损坏的条形码数据集中,它也能以令人印象深刻的 72.79% 的准确率找到最多的条形码,但仍然建议在将条形码输入条形码查找器之前对其进行预处理。 汇总表 模式 找到条形码 平均时间 每份文件所需时间 GC压力 精度提升 Faster 147/430 (33.95%) 25秒 0.058秒 高(第二代:177K) 基线 Balanced 237/430 (55.11%) 43秒 0.1秒 高(第二代:151K) 与 Faster 相比,增长了 62.32%。 Detailed 237/430 (55.11%) 5.50分钟 0.767秒 非常高(第二代:297K) +0% 对比平衡型 极致细节 313/430 (72.79%) 10.14分钟 1.414秒 Extreme(第二代:474万) 与详细数据相比,+32.08% 选择合适的速度 经过上述简要比较和上述不同场景后,开发人员通常应该从最低设置Faster开始尝试,然后逐步提高到Balanced 、 Detailed 、 ExtremeDetail ,看看输出结果之间是否存在任何显著差异。 关于使用 IronBarCode 的可扩展性,在大多数情况下, Balanced通常足以处理所有内容,开发人员只需根据图像的扭曲程度使用Detailed或ExtremeDetail模式即可。 此外,虽然这两个选项在使用Detailed和ExtremeDetail时都会对图像进行中等和重度处理,但在某些情况下,将处理过程分成两步,在将图像放入条形码阅读器之前手动应用图像滤镜,比使用单个处理过程更有价值。 有关条形码阅读器图像处理的更多信息,请参阅此处。 总的来说,这里有一个简表和总结,说明了每种不同速度适用的情况。 决策图 常见问题解答 IronBarcode中的读取速度选项是什么? IronBarcode允许您根据应用程序的需要调整读取速度,优化为更快的处理或更高的读取准确性。 如何在IronBarcode中配置条形码读取速度? 您可以通过设置条形码读卡器中的特定参数来配置IronBarcode中的读取速度,允许您优先考虑速度或准确性。 为什么我需要在IronBarcode中调整读取速度? 调整读取速度可以帮助平衡性能和准确性,这在需要高速处理或精确条形码检测的应用中至关重要。 在IronBarcode中是否可以同时实现高精度和快速读取速度? 虽然IronBarcode允许在速度和准确性之间进行可定制的平衡,但实现完美组合可能取决于具体使用案例和条形码复杂性。 在IronBarcode中选择读取速度设置的因素是什么? 因素如被扫描条形码的类型、图像质量和操作环境等会影响在IronBarcode中选择读取速度设置。 我可以在IronBarcode中动态更改读取速度设置吗? 是的,您可以在IronBarcode中动态调整读取速度设置,以适应不同的扫描条件和需求。 读取速度如何影响IronBarcode中的条形码扫描性能? IronBarcode中的读取速度设置会影响条形码的处理速度,较高的速度可能减少准确性,而较低的速度则提高精度。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Nuget 下载 1,979,979 | Version: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:1,979,979 查看许可证