IronBarcode 如何使用 讀取多個 BarCode 如何在 C# 中一次讀取多個條碼 Hairil Hasyimi Bin Omar 更新:7月 22, 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 可以多麼快速地掃描影像,找到影像中包含的每個條碼。 只需在所需的條碼類型旁邊設定ExpectMultipleBarcodes = true即可-無需樣板代碼,輕鬆便捷。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronBarcode PM > Install-Package BarCode 複製並運行這段程式碼。 var results = IronBarCode.BarcodeReader.Read("image.png", new IronBarCode.BarcodeReaderOptions { ExpectMultipleBarcodes = true, ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.AllOneDimensional }); 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronBarcode,免費試用! 免費試用30天 最小工作流程(5 個步驟) 下載用於讀取多個條碼的 C# 庫 使用Read方法從各種圖像格式中提取條碼值 利用ExpectMultipleBarcodes屬性配置讀取單一或多個條碼。 將ExpectMultipleBarcodes屬性設為 false 可提高效能 列印出條碼值 讀取多個條碼範例 預設情況下,IronBarcode 會持續掃描文件以讀取多個條碼。 然而,有時即使影像中存在多個條碼,也只會傳回一個條碼值。 為了解決這個問題,使用者可以自訂設定以啟用讀取多個條碼的功能,如下面的程式碼片段所示。 請注意, ExpectMultipleBarcodes屬性同時存在於BarcodeReaderOptions和PdfBarcodeReaderOptions類別中,允許使用者使用它來讀取影像和 PDF 文件中的條碼。 範例圖片 :path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-multiple-barcodes.cs using IronBarCode; using System; // Set the option to read multiple barcodes BarcodeReaderOptions options = new BarcodeReaderOptions() { ExpectMultipleBarcodes = true, ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional, }; // Read barcode var results = BarcodeReader.Read("testbc1.png", options); foreach (var result in results) { Console.WriteLine(result.ToString()); } Imports IronBarCode Imports System ' Set the option to read multiple barcodes Private options As New BarcodeReaderOptions() With { .ExpectMultipleBarcodes = True, .ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional } ' Read barcode Private results = BarcodeReader.Read("testbc1.png", options) For Each result In results Console.WriteLine(result.ToString()) Next result $vbLabelText $csharpLabel 透過在程式碼片段中將ExpectMultipleBarcodes設為 true,IronBarcode 會掃描整個文件中的多個條碼,並將它們儲存在BarcodeResults變數中。 使用 foreach 循環,使用者可以輕鬆存取所有條碼值並將其列印到控制台。 讀取單一條碼範例 IronBarcode 可以讀取影像或 PDF 中的單一或多個條碼。 預設情況下,即使只有一個條碼,引擎也會掃描整個文件。 但是,為了提高讀取單條碼時的效能,您可以將ExpectMultipleBarcodes設定為 false。 這樣可以防止引擎在偵測到第一個條碼後掃描整個文檔,從而加快條碼檢索速度。 下面的程式碼片段示範如何實現這一點。 範例圖片 :path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-single-barcode.cs using IronBarCode; using System; // Set the option to read single barcode BarcodeReaderOptions options = new BarcodeReaderOptions() { ExpectMultipleBarcodes = false, ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional, }; // Read barcode var results = BarcodeReader.Read("testbc1.png", options); foreach (var result in results) { Console.WriteLine(result.ToString()); } Imports IronBarCode Imports System ' Set the option to read single barcode Private options As New BarcodeReaderOptions() With { .ExpectMultipleBarcodes = False, .ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional } ' Read barcode Private results = BarcodeReader.Read("testbc1.png", options) For Each result In results Console.WriteLine(result.ToString()) Next result $vbLabelText $csharpLabel 在上面的程式碼片段中,我們使用了與之前相同的帶有多個條碼的圖像,但這次我們將ExpectMultipleBarcodes設定為 false。 因此,只會傳回第一個條碼值,掃描過程在檢索到第一個條碼後停止。 效能比較 將ExpectMultipleBarcodes設定為 false 可以大幅提高讀取影像中單一條碼的效率。 使用提供的程式碼片段,以下是同一台機器上將ExpectMultipleBarcodes設為 true 和 false 時效能差異的粗略估計: ExpectMultipleBarcodes = true ExpectMultipleBarcodes = false 0.91秒 0.10 秒 常見問題解答 如何使用 C# 讀取影像中的多個 BarCode? 要使用 C# 讀取影像中的多個條碼,您可以利用 IronBarcode 的 Read 方法,並在 BarcodeReaderOptions 或 PdfBarcodeReaderOptions 類別中將 ExpectMultipleBarcodes 屬性設定為 true。 在 IronBarcode 中設定 ExpectMultipleBarcodes 為 true 有什麼好處? 將 ExpectMultipleBarcodes 設為 true 可讓 IronBarcode 掃描並讀取影像中存在的所有條碼,這對於需要同時處理多個條碼以提高資料效率的行業來說非常重要。 讀取單一 BarCode 時,可以提高效能嗎? 是的,您可以透過在 IronBarcode 中設定 ExpectMultipleBarcodes 為 false 來改善效能。這會在偵測到第一個條碼後停止掃描過程,從而加快檢索時間。 如何用 C# 從 PDF 文件讀取 BarCode? IronBarcode 提供了使用 Read 方法和在 PdfBarcodeReaderOptions 中配置適當選項從 PDF 文件讀取條碼的功能。 如果有多個 BarCode 時只偵測到一個,該怎麼辦? 確保在 IronBarcode 中將 ExpectMultipleBarcodes 屬性設定為 true,以啟用偵測和讀取影像或 PDF 中存在的所有條碼。 如何設定 IronBarcode 從各種圖像格式讀取條碼? 要配置 IronBarcode 從各種圖像格式讀取條碼,您應該使用 Read 方法,並在 BarcodeReaderOptions 類中設定 ExpectMultipleBarcodes 屬性。 使用設定為 true 的 ExpectMultipleBarcodes 與設定為 false 的 ExpectMultipleBarcodes 在效能上有何差異? 性能差異非常顯著;將 ExpectMultipleBarcodes 設為 false 可縮短處理時間,因為它會在偵測到第一個條碼後停止掃描,而將其設定為 true 則會掃描所有條碼,這會耗費更長的時間。 是否有 C# 函式庫可有效讀取多個 BarCode? 是的,IronBarcode 是一個 C# 函式庫,可從影像和 PDF 文件中有效讀取多個條碼,提供改善效能和簡化資料處理的工具。 Hairil Hasyimi Bin Omar 立即與工程團隊聊天 軟體工程師 和所有优秀的工程师一样,Hairil 是个努力学习者。他正在细化自己的 C# 、Python 和 Java 知识,将这些知识应用于 Iron Software 各个团队成员以增加价值。Hairil 自马来西亚 Universiti Teknologi MARA 加入 Iron Software 团队,并以化学与工艺工程学士学位毕业。 準備好開始了嗎? Nuget 下載 1,979,979 | Version: 2025.11 剛發表 免費下載 NuGet 下載總數:1,979,979 檢視授權