使用 IRONBARCODE C# 二維碼閱讀器(初學者的逐步教學) Curtis Chau 更新:2025年6月22日 下載 IronBarcode NuGet 下載 DLL 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 在當今數位化驅動的世界中,二維碼(快速回應碼)已經無所不在,無縫連接了實體世界和數位世界。 從行銷到物流,從金融到醫療保健,二維碼在促進高效數據交換方面發揮關鍵作用。 在本文中,我們將深入探討 C# 開發領域,探索IronQR (市場上最好的二維碼庫之一)如何幫助開發人員利用二維碼識別功能,輕鬆解碼數據,並在各個領域進行創新。 Iron Software的 IronQR 是一款功能強大的 .NET 二維碼閱讀器庫,表現出色。 IronQR 實現的先進機器學習模型使您的應用程式能夠以無與倫比的準確性和效率解碼二維碼,即使在具有挑戰性的場景下也是如此。 如何使用 IronQR 和 C# 讀取二維碼 使用 .NET Windows 窗體應用程式範本建立Visual Studio專案。 從NuGet套件管理器安裝IronQR 。 使用 AForge 函式庫從相機取得二維碼影像。 使用 IronQR 讀取二維碼。 IronQR是一款出色的 C# 二維碼閱讀器庫,旨在 .NET 框架內掃描和產生二維碼影像。 IronQR 利用尖端的機器學習技術,將二維碼讀取提升到了前所未有的水平。 無論您是掃描影像、視訊還是即時相機畫面中的二維碼,這款基於機器學習的解決方案都能保證快速可靠的資訊檢索。 這種創新方法不僅簡化了資料擷取流程,而且透過區分真實的二維碼和潛在的威脅來增強安全性。 憑藉其直覺的 API,開發人員可以在幾分鐘內將二維碼功能無縫整合到他們的 .NET 專案中。 IronQR 可與 .NET Core(8、7、6、5 和 3.1+)、.NET Standard(2.0+)和 .NET Framework(4.6.2+)無縫整合。 目前的 .NET Core 版本擴展了對 Linux、Unix 和 macOS 等客戶端作業系統的支持,並與開發行動應用程式相容。 先決條件 Visual Studio:請確保您已安裝 Visual Studio 或任何其他 .NET 開發環境。 2.相容的攝影機:確保攝影機已連接到您的裝置。 NuGet 套件管理器:驗證您是否可以使用NuGet來管理專案中的套件。 步驟 1:使用 .NET Windows 窗體應用程式範本建立 Visual Studio 項目 讓我們先建立一個 Windows Forms .NET 應用程序,用於從相機視訊串流或映像檔讀取二維碼條碼。 開啟 Visual Studio,選擇"建立新專案",然後選擇".NET Windows 窗體應用程式"範本。 Visual Studio 安裝 點擊"下一步",然後輸入項目名稱。 項目命名 選擇所需的 .NET 版本,然後按一下"建立"按鈕。 創建專案 步驟 2:從 NuGet 套件管理器安裝 IronQR IronQR可以使用NuGet套件管理器或 Visual Studio 套件管理器進行安裝。 NuGet 安裝 以下展示如何使用 Visual Studio 來實作。 Visual Studio NuGet 步驟 3:使用 AForge 函式庫從相機取得二維碼影像。 要從相機設備掃描二維碼,我們需要安裝AForge.Video.DirectShow庫。 這可以透過 Visual Studio 套件管理器完成。 右鍵點選解決方案資源管理器,開啟程式包管理器。 AForge 安裝步驟 1 也可以使用NuGet套件控制台安裝此程式庫,如下所示。 點選"安裝"按鈕安裝庫檔案。 AForge 安裝步驟 2 步驟 4:使用 IronQR 讀取二維碼 下一步是在窗體中建立一個 PictureBox 元件,該元件用於掃描連接到機器的相機裝置中的二維碼影像。 這可以透過從工具箱中拖放來完成。 此 PictureBox 用於讀取相機設備中的二維碼資料。 新增圖片框 接下來,拖放一個文字方塊來顯示讀取的二維碼。 新增文字框 加入以下程式碼,即可使用IronQR讀取和解碼二維碼。 using AForge.Video.DirectShow; using AForge.Video; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; using IronQR; namespace ReadQR { public partial class Form1 : Form { // Declare a video capture device private VideoCaptureDevice videoSource; public Form1() { InitializeComponent(); this.Load += Form1_Load; this.FormClosing += Form1_FormClosing; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // Stop the video source when the form is closing if (videoSource != null && videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); } } private void Form1_Load(object sender, EventArgs e) { // Retrieve video input devices connected to the machine FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count > 0) { // Use the first available video device videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString); videoSource.NewFrame += VideoSource_NewFrame; videoSource.Start(); } else { MessageBox.Show("No video devices found."); Close(); } } private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs) { // Update the PictureBox with the new frame from the camera pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone(); var image = (Bitmap)eventArgs.Frame.Clone(); // Set the license key for IronQR. Replace "YourKey" with your actual key License.LicenseKey = "YourKey"; // Prepare the image for QR code reading QrImageInput imageInput = new QrImageInput(image); // Create a QR reader object QrReader reader = new QrReader(); // Read QR codes from the image IEnumerable<QrResult> results = reader.Read(imageInput); // Display the first QR code result in a MessageBox if (results.Any()) { MessageBox.Show(results.First().Value); } } } } using AForge.Video.DirectShow; using AForge.Video; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; using IronQR; namespace ReadQR { public partial class Form1 : Form { // Declare a video capture device private VideoCaptureDevice videoSource; public Form1() { InitializeComponent(); this.Load += Form1_Load; this.FormClosing += Form1_FormClosing; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // Stop the video source when the form is closing if (videoSource != null && videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); } } private void Form1_Load(object sender, EventArgs e) { // Retrieve video input devices connected to the machine FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count > 0) { // Use the first available video device videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString); videoSource.NewFrame += VideoSource_NewFrame; videoSource.Start(); } else { MessageBox.Show("No video devices found."); Close(); } } private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs) { // Update the PictureBox with the new frame from the camera pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone(); var image = (Bitmap)eventArgs.Frame.Clone(); // Set the license key for IronQR. Replace "YourKey" with your actual key License.LicenseKey = "YourKey"; // Prepare the image for QR code reading QrImageInput imageInput = new QrImageInput(image); // Create a QR reader object QrReader reader = new QrReader(); // Read QR codes from the image IEnumerable<QrResult> results = reader.Read(imageInput); // Display the first QR code result in a MessageBox if (results.Any()) { MessageBox.Show(results.First().Value); } } } } Imports AForge.Video.DirectShow Imports AForge.Video Imports System Imports System.Collections.Generic Imports System.Drawing Imports System.Linq Imports System.Windows.Forms Imports IronQR Namespace ReadQR Partial Public Class Form1 Inherits Form ' Declare a video capture device Private videoSource As VideoCaptureDevice Public Sub New() InitializeComponent() AddHandler Me.Load, AddressOf Form1_Load AddHandler Me.FormClosing, AddressOf Form1_FormClosing End Sub Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) ' Stop the video source when the form is closing If videoSource IsNot Nothing AndAlso videoSource.IsRunning Then videoSource.SignalToStop() videoSource.WaitForStop() End If End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) ' Retrieve video input devices connected to the machine Dim videoDevices As New FilterInfoCollection(FilterCategory.VideoInputDevice) If videoDevices.Count > 0 Then ' Use the first available video device videoSource = New VideoCaptureDevice(videoDevices(0).MonikerString) AddHandler videoSource.NewFrame, AddressOf VideoSource_NewFrame videoSource.Start() Else MessageBox.Show("No video devices found.") Close() End If End Sub Private Sub VideoSource_NewFrame(ByVal sender As Object, ByVal eventArgs As NewFrameEventArgs) ' Update the PictureBox with the new frame from the camera pictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap) Dim image = DirectCast(eventArgs.Frame.Clone(), Bitmap) ' Set the license key for IronQR. Replace "YourKey" with your actual key License.LicenseKey = "YourKey" ' Prepare the image for QR code reading Dim imageInput As New QrImageInput(image) ' Create a QR reader object Dim reader As New QrReader() ' Read QR codes from the image Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput) ' Display the first QR code result in a MessageBox If results.Any() Then MessageBox.Show(results.First().Value) End If End Sub End Class End Namespace $vbLabelText $csharpLabel 輸入影像檔案 二維碼中編碼的文字是:我愛 IronQR ! QR 圖碼範例 輸出 ! QR 圖碼結果 範例程式碼解釋 我們在 Windows 表單中註冊了兩個事件: Form1_Load和Form1_FormClosing 。 我們也向 AForge.Video.DirectShow 庫中的videoSource實例註冊了VideoSource_NewFrame 。 我們讀取即時視訊串流中的二維碼。 當偵測到二維碼時,我們會顯示一個包含解碼文字的訊息方塊。 授權(可免費試用) IronQR需要許可證密鑰。 您可以從此網站取得試用金鑰。 此 key 需要放在 appsettings.json 中。 { "IronQR.LicenseKey": "MYLICENSE.KEY.TRIAL" } 請提供您的電子郵件地址以取得試用許可證,提交後,金鑰將透過電子郵件發送給您。 許可證密鑰 結論 總之,二維碼已經超越了其起源,成為我們數位生態系統中不可或缺的一部分。 借助IronQR ,C# 開發人員可以利用二維碼識別的強大功能,輕鬆解碼各種類型的二維碼中的數據,並在各個領域進行創新。 隨著二維碼不斷發展並融入新技術,它們在促進無縫資料交換和提升使用者體驗方面的重要性只會越來越大。 運用IronQR擁抱二維碼的潛力,開啟 C# 開發創新與高效率的旅程。 常見問題解答 如何設定一個C#專案來讀取二維碼? 要設定一個用於讀取二維碼的 C# 項目,請先在 Visual Studio 中建立一個新的 Windows 窗體應用程式。從 NuGet 套件管理器安裝 IronQR 庫,並確保您擁有 AForge.Video.DirectShow 庫以從攝影機擷取視訊串流。 使用 IronQR 進行二維碼讀取有哪些好處? IronQR 利用先進的機器學習模型,提供強大的二維碼讀取功能。即使在複雜條件下,它也能確保準確解碼,並支援各種 .NET 框架和作業系統。 如何在C#應用程式中使用IronQR解碼二維碼? 若要在 C# 應用程式中使用 IronQR 解碼 QR 碼,請使用 AForge 從相機畫面擷取影像,然後使用 IronQR 庫處理和解碼擷取影像中的 QR 碼。 IronQR能否解碼即時視訊串流中的二維碼? 是的,IronQR 可以透過與 AForge.Video.DirectShow 庫整合來解碼即時視訊串流中的二維碼,從而捕獲幀並即時處理它們。 用 C# 建立二維碼閱讀器需要哪些必備庫? 在 C# 中建立 QR 碼閱讀器所需的基本庫包括用於解碼 QR 碼的 IronQR 和用於從攝影機擷取視訊串流的 AForge.Video.DirectShow。 IronQR 如何確保二維碼解碼過程中的資料完整性? IronQR 透過準確區分真假二維碼和潛在威脅,增強安全性並確保資料完整性,從而保持解碼資訊的可靠性。 是否可以使用 IronQR 掃描圖片中的二維碼? 是的,IronQR不僅可以掃描即時視訊串流中的二維碼,還可以掃描靜態影像中的二維碼,從而為各種應用需求提供靈活性。 如何取得IronQR的試用授權? 您可以從 Iron Software 網站獲得 IronQR 的試用許可證,透過將試用金鑰放入應用程式的appsettings.json檔案中來測試該程式庫的功能。 PictureBox 元件在二維碼閱讀器應用程式中扮演什麼角色? 在二維碼閱讀器應用程式中,PictureBox 元件顯示來自相機的即時視訊串流,使 IronQR 能夠捕捉和解碼傳入幀中的二維碼。 如何排查C#中二維碼解碼的問題? 如果遇到二維碼解碼問題,請確保 IronQR 和 AForge 庫已正確安裝,檢查攝影機畫面是否已正確集成,並驗證您的應用程式是否已正確擷取和處理視訊畫面。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 相關文章 更新2026年1月22日 ASP.NET 條碼掃描器教學:C# 條碼產生器指南 學習如何使用 IronBarcode 在 ASP.NET 中掃描條碼 閱讀更多 發表日期 2026年1月21日 C# 資料矩陣產生器:IronBarcode 完整指南 C# 資料矩陣條碼產生器教學。學習如何使用 IronBarcode 建立 ECC200 資料矩陣條碼。提供簡單的二維條碼生成程式碼範例。 閱讀更多 發表日期 2026年1月21日 使用 IronBarcode 的 Xamarin 條碼產生器建立專業品質的條碼 使用 IronBarcode 和 Xamarin 條碼產生器,學習如何建立專業品質的條碼。 閱讀更多 如何使用 C# 在 ASP.NET 中產生條碼
發表日期 2026年1月21日 C# 資料矩陣產生器:IronBarcode 完整指南 C# 資料矩陣條碼產生器教學。學習如何使用 IronBarcode 建立 ECC200 資料矩陣條碼。提供簡單的二維條碼生成程式碼範例。 閱讀更多
發表日期 2026年1月21日 使用 IronBarcode 的 Xamarin 條碼產生器建立專業品質的條碼 使用 IronBarcode 和 Xamarin 條碼產生器,學習如何建立專業品質的條碼。 閱讀更多