IronBarcode 開始 C# 和 VB.NET 應用程式中的條碼和二維碼 Curtis Chau 更新:6月 10, 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 軟體庫,在 C# 和所有其他 .NET 語言中讀取和寫入條碼非常簡單。 安裝 IronBarcode 旅程的第一步是安裝 IronBarcode,可以透過從 NuGet 下載或下載 DLL來完成。 若要安裝 IronBarcode NuGet 套件,您可以使用 Visual Studio 的 NuGet 套件管理器: Install-Package BarCode 或者,您也可以使用 dotnet CLI 進行安裝: dotnet add package IronBarCode 讀取條碼或二維碼 使用 IronBarcode 讀取條碼只需要一行程式碼。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-1.cs using IronBarCode; BarcodeResults results = BarcodeReader.Read("QuickStart.jpg"); if (results != null) { foreach (BarcodeResult result in results) { Console.WriteLine(result.Text); } } Imports IronBarCode Private results As BarcodeResults = BarcodeReader.Read("QuickStart.jpg") If results IsNot Nothing Then For Each result As BarcodeResult In results Console.WriteLine(result.Text) Next result End If $vbLabelText $csharpLabel 只需一行程式碼,即可有效檢測並掃描輸入文件中的所有類型條碼——一步到位,滿足您的所有需求!此方法支援多種影像格式,例如 JPEG、PNG 和 BMP,以及 PDF 和多幀格式,例如 GIF 和 TIFF。 為了提高效能,提供了可自訂的配置選項。 為了提高讀取速度,您可以建立一個BarcodeReaderOptions對象,並將Speed設定配置為更好的效能。 預設為Balanced ,但可以選擇Faster選項來跳過某些檢查。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-2.cs using IronBarCode; BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions() { ExpectMultipleBarcodes = false, ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128, CropArea = new System.Drawing.Rectangle(100, 200, 300, 400), }; BarcodeResults result = BarcodeReader.Read("QuickStart.jpg", myOptionsExample); if (result != null) { Console.WriteLine(result.First().Text); } Imports IronBarCode Private myOptionsExample As New BarcodeReaderOptions() With { .ExpectMultipleBarcodes = False, .ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128, .CropArea = New System.Drawing.Rectangle(100, 200, 300, 400) } Private result As BarcodeResults = BarcodeReader.Read("QuickStart.jpg", myOptionsExample) If result IsNot Nothing Then Console.WriteLine(result.First().Text) End If $vbLabelText $csharpLabel 您也可以將ScanMode設定為OnlyBasicScan ,以最佳化讀取過程。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-3.cs using IronBarCode; BarcodeResults results = BarcodeReader.Read("MultipleBarcodes.png"); // Loop through the results foreach (BarcodeResult result in results) { string value = result.Value; Bitmap img = result.BarcodeImage; BarcodeEncoding barcodeType = result.BarcodeType; byte[] binary = result.BinaryValue; Console.WriteLine(result.Value); } Imports IronBarCode Private results As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.png") ' Loop through the results For Each result As BarcodeResult In results Dim value As String = result.Value Dim img As Bitmap = result.BarcodeImage Dim barcodeType As BarcodeEncoding = result.BarcodeType Dim binary() As Byte = result.BinaryValue Console.WriteLine(result.Value) Next result $vbLabelText $csharpLabel 其他配置包括指定要掃描的條碼格式,這可以透過減少不必要的掃描來加快處理速度。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-4.cs using IronBarCode; BarcodeResults pagedResults = BarcodeReader.Read("MultipleBarcodes.pdf"); // Loop through the results foreach (BarcodeResult result in pagedResults) { int pageNumber = result.PageNumber; string value = result.Value; Bitmap img = result.BarcodeImage; BarcodeEncoding barcodeType = result.BarcodeType; byte[] binary = result.BinaryValue; Console.WriteLine(result.Value); } // or from a multi-page TIFF scan with image correction: BarcodeResults multiFrameResults = BarcodeReader.Read(inputImage: "Multiframe.tiff", new BarcodeReaderOptions { Speed = ReadingSpeed.Detailed, ExpectMultipleBarcodes = true, ExpectBarcodeTypes = BarcodeEncoding.Code128, Multithreaded = false, RemoveFalsePositive = false, ImageFilters = null }); Imports IronBarCode Private pagedResults As BarcodeResults = BarcodeReader.Read("MultipleBarcodes.pdf") ' Loop through the results For Each result As BarcodeResult In pagedResults Dim pageNumber As Integer = result.PageNumber Dim value As String = result.Value Dim img As Bitmap = result.BarcodeImage Dim barcodeType As BarcodeEncoding = result.BarcodeType Dim binary() As Byte = result.BinaryValue Console.WriteLine(result.Value) Next result ' or from a multi-page TIFF scan with image correction: Dim multiFrameResults As BarcodeResults = BarcodeReader.Read(inputImage:= "Multiframe.tiff", New BarcodeReaderOptions With { .Speed = ReadingSpeed.Detailed, .ExpectMultipleBarcodes = True, .ExpectBarcodeTypes = BarcodeEncoding.Code128, .Multithreaded = False, .RemoveFalsePositive = False, .ImageFilters = Nothing }) $vbLabelText $csharpLabel 條碼編寫 要使用 IronBarcode 來寫條碼,我們使用BarcodeWriter類別。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-5.cs using IronBarCode; GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128); myBarcode.SaveAsImage("myBarcode.png"); Imports IronBarCode Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128) myBarcode.SaveAsImage("myBarcode.png") $vbLabelText $csharpLabel 條碼樣式 IronBarcode 提供了多種選項來操控條碼的視覺呈現。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-7.cs using IronBarCode; GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128); myBarcode.AddAnnotationTextAboveBarcode("Product URL:"); myBarcode.AddBarcodeValueTextBelowBarcode(); myBarcode.SetMargins(100); myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.Purple); // All major image formats supported as well as PDF and HTML myBarcode.SaveAsPng("myBarcode.png"); Imports IronBarCode Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128) myBarcode.AddAnnotationTextAboveBarcode("Product URL:") myBarcode.AddBarcodeValueTextBelowBarcode() myBarcode.SetMargins(100) myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.Purple) ' All major image formats supported as well as PDF and HTML myBarcode.SaveAsPng("myBarcode.png") $vbLabelText $csharpLabel 將條碼匯出為 HTML IronBarcode 可以將條碼匯出為 HTML 文件或 HTML 內容的一部分。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-8.cs using IronBarCode; QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf"); Imports IronBarCode QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf") $vbLabelText $csharpLabel 產生二維碼 對於二維碼,請使用QRCodeWriter類,該類別提供了針對二維碼特定功能(例如糾錯)的額外配置。 :path=/static-assets/barcode/content-code-examples/get-started/get-started-9.cs using IronBarCode; using IronSoftware.Drawing; QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png"); GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo); myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf"); Imports IronBarCode Imports IronSoftware.Drawing Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png") Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", qrCodeLogo) myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen).SaveAsPdf("MyQRWithLogo.pdf") $vbLabelText $csharpLabel 支援的條碼格式 IronBarcode支援多種常用條碼格式的讀取和寫入: QR碼、微型QR碼和矩形微型QR碼(rMQR碼) 。 其他二維條碼,例如Aztec 、 Data Matrix 、 MaxiCode和PDF417 。 堆疊式線性條碼,例如Databar 。 傳統的一維條碼格式,例如UPC-A 、 UPC-E 、 EAN-8 、 EAN-13 、 Codabar 、 ITF 、 MSI和Plessey 。 為什麼選擇 IronBarcode? IronBarcode 為開發人員提供了一個友好、易於使用的 API,用於讀取和寫入 .NET 條碼,該 API 在實際使用場景中針對準確性、精確性和速度進行了最佳化。 例如, BarcodeWriter類別會自動驗證和修正 UPCA 和 UPCE 條碼的"校驗和",並處理數位格式約束。 IronBarcode 可協助開發人員選擇最適合其資料的條碼格式。 該庫功能強大,具有自動旋轉和影像去噪等影像預處理技術,可最大限度地提高條碼檢測成功率。 展望未來 為了充分利用 IronBarcode,我們鼓勵您閱讀本文檔部分的教學課程,並造訪我們的GitHub 頁面。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 1,979,979 | Version: 2025.11 剛發表 免費下載 NuGet 下載總數:1,979,979 檢視授權