使用IRONBARCODE 使用.NET條碼閱讀器SDK Jordi Bardia 更新:8月 5, 2025 下載 IronBarcode NuGet 下載 DLL 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 條碼掃描是許多應用領域的重要功能,從庫存管理到零售和物流都離不開它。 透過將條碼讀取功能整合到 .NET 應用程式中,您可以簡化資料收集、自動化工作流程並提高效率。 IronBarcode 是一個功能強大的 .NET 函式庫,它讓條碼的處理變得簡單。 借助此工具,您可以讀取圖像、視訊串流和 PDF 檔案中的條碼,以及產生二維碼。 本文將向您展示如何將條碼掃描整合到您的 .NET 應用程式中,重點介紹如何建立 API 或 Web 應用程式整合來公開條碼掃描功能。 IronBarcode整合的最佳用例 IronBarcode 非常適合用於: *庫存管理系統*– 自動掃描條碼以追蹤產品和庫存水準。 物流應用– 處理掃描的條碼影像,用於出貨、收貨和包裹追蹤。 零售POS系統– 驗證銷售交易和價格查詢的條碼掃描。 文件處理**– 從 PDF 發票、收據或身分證中提取條碼資料。 如何在 .NET 中建立條碼讀取器 SDK 要建立一個可以作為服務在應用程式中公開的條碼閱讀器,您需要將 IronBarcode 整合到 REST API 或 Web 應用程式中。以下範例展示如何使用 ASP.NET Core 實作此操作。 1.安裝用於在 C# 中讀取條碼的 .NET 函式庫 建立一個可重複使用的條碼掃描類別。 發展從不同來源讀取條碼的方法。 將條碼影像讀取功能整合到您的應用程式中。 測試並優化效能。 開始之前 如果您還沒有下載 IronBarcode,請立即下載到您的專案中。 請確保您擁有適用於您預期用途的正確許可證金鑰。 請注意,透過公共 API 公開 IronBarcode 的功能或將其轉售為獨立服務需要額外的許可(SDK、OEM 或 SaaS)。 在繼續操作之前,請務必了解許可證方面的注意事項。 建立條碼掃描器類 在設定好 IronBarcode 並將其安裝到您的專案中之後,您可以建立一個可重複使用的條碼掃描器類,該類別整合了 IronBarcode 的功能並將其公開為 API 端點。 using IronBarCode; using System.IO; namespace BarcodeIntegration { public class BarcodeScanner { static BarcodeScanner() { // Set the license key IronBarCode.License.LicenseKey = "Your-License-Key"; } // Method to read a barcode from an image file public string ReadBarcodeFromImage(string imagePath) { try { // Try to read the barcode from the given image path var barcode = BarcodeReader.Read(imagePath); return barcode?.ToString() ?? "No Barcode Found"; // Return the barcode string or indicate no barcode was found } catch (Exception ex) { // Return an error message if an exception occurs return $"Error reading barcode: {ex.Message}"; } } // Method to read a barcode from a stream (e.g., file upload or memory stream) public string ReadBarcodeFromStream(Stream inputStream) { try { // Try to read the barcode from the given stream var barcode = BarcodeReader.Read(inputStream); return barcode?.ToString() ?? "No barcode found"; } catch (Exception ex) { return $"Error reading barcode: {ex.Message}"; } } // Method to read a barcode from a PDF file public string ReadBarcodeFromPdf(string filePath) { try { // Try to read the barcode from the given PDF file path var barcode = BarcodeReader.ReadPdf(filePath); return barcode?.ToString() ?? "No barcode found"; } catch (Exception ex) { return $"Error reading barcode: {ex.Message}"; } } } } using IronBarCode; using System.IO; namespace BarcodeIntegration { public class BarcodeScanner { static BarcodeScanner() { // Set the license key IronBarCode.License.LicenseKey = "Your-License-Key"; } // Method to read a barcode from an image file public string ReadBarcodeFromImage(string imagePath) { try { // Try to read the barcode from the given image path var barcode = BarcodeReader.Read(imagePath); return barcode?.ToString() ?? "No Barcode Found"; // Return the barcode string or indicate no barcode was found } catch (Exception ex) { // Return an error message if an exception occurs return $"Error reading barcode: {ex.Message}"; } } // Method to read a barcode from a stream (e.g., file upload or memory stream) public string ReadBarcodeFromStream(Stream inputStream) { try { // Try to read the barcode from the given stream var barcode = BarcodeReader.Read(inputStream); return barcode?.ToString() ?? "No barcode found"; } catch (Exception ex) { return $"Error reading barcode: {ex.Message}"; } } // Method to read a barcode from a PDF file public string ReadBarcodeFromPdf(string filePath) { try { // Try to read the barcode from the given PDF file path var barcode = BarcodeReader.ReadPdf(filePath); return barcode?.ToString() ?? "No barcode found"; } catch (Exception ex) { return $"Error reading barcode: {ex.Message}"; } } } } Imports IronBarCode Imports System.IO Namespace BarcodeIntegration Public Class BarcodeScanner Shared Sub New() ' Set the license key IronBarCode.License.LicenseKey = "Your-License-Key" End Sub ' Method to read a barcode from an image file Public Function ReadBarcodeFromImage(ByVal imagePath As String) As String Try ' Try to read the barcode from the given image path Dim barcode = BarcodeReader.Read(imagePath) Return If(barcode?.ToString(), "No Barcode Found") ' Return the barcode string or indicate no barcode was found Catch ex As Exception ' Return an error message if an exception occurs Return $"Error reading barcode: {ex.Message}" End Try End Function ' Method to read a barcode from a stream (e.g., file upload or memory stream) Public Function ReadBarcodeFromStream(ByVal inputStream As Stream) As String Try ' Try to read the barcode from the given stream Dim barcode = BarcodeReader.Read(inputStream) Return If(barcode?.ToString(), "No barcode found") Catch ex As Exception Return $"Error reading barcode: {ex.Message}" End Try End Function ' Method to read a barcode from a PDF file Public Function ReadBarcodeFromPdf(ByVal filePath As String) As String Try ' Try to read the barcode from the given PDF file path Dim barcode = BarcodeReader.ReadPdf(filePath) Return If(barcode?.ToString(), "No barcode found") Catch ex As Exception Return $"Error reading barcode: {ex.Message}" End Try End Function End Class End Namespace $vbLabelText $csharpLabel BarcodeScanner類別抽象化了 IronBarcode 的功能,使其易於整合到任何 .NET 應用程式中。 讓我們來詳細了解這裡包含的不同方法: 條碼讀取法 以下每種方法都嘗試從不同類型的輸入中讀取條碼: ReadBarcodeFromImage(string imagePath) : 從映像檔中讀取條碼。 ReadBarcodeFromStream(Stream inputStream) : 從輸入流(例如,檔案上傳或記憶體流)讀取條碼。 ReadBarcodeFromPdf(string filePath) : 從 PDF 檔案中讀取條碼。 每個方法都會嘗試讀取條碼數據,並傳回條碼字串;如果未找到條碼或發生異常,則傳回錯誤訊息。 透過 REST API 公開條碼讀取功能 若要允許外部應用程式使用您的條碼掃描功能,您可以使用 ASP.NET Core 將其公開為 REST API。 以下是一個操作範例: using Microsoft.AspNetCore.Mvc; using System.IO; using Microsoft.AspNetCore.Http; using BarcodeIntegration; [ApiController] [Route("api/barcode")] public class BarcodeController : ControllerBase { private readonly BarcodeScanner _barcodeScanner; public BarcodeController() { // Initialize the BarcodeScanner class _barcodeScanner = new BarcodeScanner(); } // POST endpoint to read barcode from an uploaded image [HttpPost("read-from-image")] public IActionResult ReadFromImage(IFormFile file) { using var stream = file.OpenReadStream(); var result = _barcodeScanner.ReadBarcodeFromStream(stream); return Ok(new { Barcode = result }); // Return the barcode reading result } } using Microsoft.AspNetCore.Mvc; using System.IO; using Microsoft.AspNetCore.Http; using BarcodeIntegration; [ApiController] [Route("api/barcode")] public class BarcodeController : ControllerBase { private readonly BarcodeScanner _barcodeScanner; public BarcodeController() { // Initialize the BarcodeScanner class _barcodeScanner = new BarcodeScanner(); } // POST endpoint to read barcode from an uploaded image [HttpPost("read-from-image")] public IActionResult ReadFromImage(IFormFile file) { using var stream = file.OpenReadStream(); var result = _barcodeScanner.ReadBarcodeFromStream(stream); return Ok(new { Barcode = result }); // Return the barcode reading result } } Imports Microsoft.AspNetCore.Mvc Imports System.IO Imports Microsoft.AspNetCore.Http Imports BarcodeIntegration <ApiController> <Route("api/barcode")> Public Class BarcodeController Inherits ControllerBase Private ReadOnly _barcodeScanner As BarcodeScanner Public Sub New() ' Initialize the BarcodeScanner class _barcodeScanner = New BarcodeScanner() End Sub ' POST endpoint to read barcode from an uploaded image <HttpPost("read-from-image")> Public Function ReadFromImage(ByVal file As IFormFile) As IActionResult Dim stream = file.OpenReadStream() Dim result = _barcodeScanner.ReadBarcodeFromStream(stream) Return Ok(New With {Key .Barcode = result}) ' Return the barcode reading result End Function End Class $vbLabelText $csharpLabel Swagger UI 使用適用於 .NET 的條碼閱讀器 SDK:圖 1 輸出 使用適用於 .NET 的條碼閱讀器 SDK:圖 2 該 API 公開了一個 POST 端點,使用者可以在該端點上傳條碼圖像,API 將傳回條碼資料。 這樣一來,其他系統或前端應用程式就可以以服務的形式與您的條碼掃描器進行互動。 進階功能 為了進一步增強 SDK,可以考慮加入以下內容: 1.支援多種條碼類型: IronBarcode 支援讀取多種條碼。 您可以新增選項來配置您的 SDK,使其能夠一次接受多個條碼。 舉例來說 ```csharp public string ReadBarcodeFromImage(string imagePath) { try { BarcodeReaderOptions options = new BarcodeReaderOptions() { ExpectMultipleBarcodes = true, ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional, }; foreach (var barcode in BarcodeReader.Read(imagePath, options)) { return barcode.ToString(); } return "No barcode found"; } catch (Exception ex) { return $"Error reading barcode: {ex.Message}"; } } ``` 2.錯誤處理:擴展錯誤處理和日誌記錄,為 SDK 用戶提供更好的診斷。 3.批次處理:如果要處理一組影像中的多個條碼,可以建立接受影像陣列或流的方法。 4.客製化:提供條碼檢測參數的配置選項,例如準確度、速度和支援的條碼類型。 許可證上的考慮因素 如前所述,IronBarcode SDK 旨在整合到您的內部應用程式中,透過 API 公開它需要額外的許可。 在將 IronBarcode 作為服務的一部分(例如公共 API)公開之前,您必須獲得必要的許可(SDK、OEM 或 SaaS)。 未經許可,請勿將 IronBarcode 以獨立 SDK 轉售,或透過面向公眾的 API 公開,除非您已確保您的許可涵蓋此用途。 立即免費試用 IronBarcode 體驗IronBarcode的創新力量。 試試我們的免費試用版,探索適用於 .NET 應用程式的無縫條碼產生、讀取和編輯功能。 IronBarcode 擁有先進的功能、卓越的性能和用戶友好的介面,是滿足您所有條碼需求的終極解決方案。 立即開始免費試用,提升您的專案水準。 常見問題解答 如何將 BarCode 閱讀器整合到 .NET 應用程式中? 您可以使用 IronBarcode library 將條碼閱讀器整合到 .NET 應用程式中。首先,安裝 IronBarcode,然後建立一個條碼掃描的類,並實作從影像、串流和 PDF 讀取條碼的方法。最後,測試並優化您的設定。 如何以 REST API 的形式公開條碼讀取功能? 若要以 REST API 的形式公開條碼讀取功能,請使用 ASP.NET Core 建立網頁應用程式。納入 IronBarcode 函式庫,開發一個 BarcodeScanner 類別,並定義 API 端點,使用 ReadBarcodeFromImage 和 ReadBarcodeFromStream 等方法讀取條碼。 使用 .NET 條碼函式庫可以讀取哪些條碼類型? IronBarcode for .NET 之類的 .NET 條碼函式庫可以讀取各種條碼類型,包括 QR code、Code 128、UPC 和 EAN。您可以通過設置檢測參數來配置該程式庫,以便同時檢測多種條碼類型。 在 .NET 中讀取 BarCode 時,如何處理錯誤? 處理條碼讀取中的錯誤可以通過使用 IronBarcode 在您的條碼掃描方法中實現強大的錯誤處理來實現。確保您能捕捉到異常,並提供有意義的回饋或重試機制,以提高條碼讀取過程的可靠性。 在公共 API 中使用 .NET BarCode 程式庫有哪些授權要求? 在公共 API 中使用 IronBarcode 時,您必須確保獲得適當的授權。這包括取得 SDK、OEM 或 SaaS 授權,因為以獨立服務或公共 API 的方式公開函式庫的功能需要額外的權限。 我可以使用 .NET 函式庫批次處理多個 BarCode 掃描嗎? 是的,您可以使用 IronBarcode 批次處理多個條碼掃描。該函式庫允許您在單一操作中讀取多個條碼,這對於有效率地處理大型影像集或文件特別有用。 是否有 .NET BarCode 程式庫的試用版? 是的,IronBarcode 提供了免費的試用版,允許您在 .NET 應用程式中探索其在條碼生成、讀取和編輯方面的功能。這個試用版可以幫助您在做出購買決定之前評估這個庫。 Jordi Bardia 立即與工程團隊聊天 軟體工程師 Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。 相關文章 發表日期 12月 18, 2025 IronBarcode 與開源條碼閱讀器 .NET 的對比 了解如何使用IronBarcode在C#中讀取條碼 閱讀更多 發表日期 12月 18, 2025 C# 資料矩陣產生器:IronBarcode 完整指南 數據矩陣生成器C#教程。學習如何使用IronBarcode創建ECC200數據矩陣條碼。簡單的2D條碼生成代碼示例。 閱讀更多 發表日期 10月 19, 2025 如何使用VB.NET在Crystal Reports中打印條碼 在VB.NET中使用IronBarcode SDK在Crystal Reports中生成和打印條碼的分步教程,確保可靠的條碼集成。 閱讀更多 如何使用IronBarcode創建MAUI條碼掃描器如何使用IronBarcode讀取多個...
發表日期 12月 18, 2025 C# 資料矩陣產生器:IronBarcode 完整指南 數據矩陣生成器C#教程。學習如何使用IronBarcode創建ECC200數據矩陣條碼。簡單的2D條碼生成代碼示例。 閱讀更多
發表日期 10月 19, 2025 如何使用VB.NET在Crystal Reports中打印條碼 在VB.NET中使用IronBarcode SDK在Crystal Reports中生成和打印條碼的分步教程,確保可靠的條碼集成。 閱讀更多