IRONSOFTWAREHOME

Barcodes & QRs in C# & VB.NET Applications

Curtis Chau
Curtis Chau
Updated: 2026年6月29日

透過我們的 IronBarcode 程式庫,在 C# 及所有其他 .NET 語言中讀取與寫入 BarCode 變得輕而易舉。

安裝 IronBarcode

這段旅程的第一步是安裝 IronBarcode,您可以透過 NuGet 下載,或直接下載 DLL 檔案

若要安裝 IronBarcode NuGet 套件,您可以使用 Visual Studio 的 NuGet 套件管理員:

PM > Install-Package BarCode

此外,您也可以透過 .NET CLI 進行安裝:

dotnet add package IronBarCode

讀取 BarCode 或 QR 碼

using IronBarcode 讀取 BARCODE 只需一行程式碼。

using IronBarCode;

BarcodeResults results = BarcodeReader.Read("QuickStart.jpg");
if (results != null)
{
    foreach (BarcodeResult result in results)
    {
        Console.WriteLine(result.Text);
    }
}

只需這一行程式碼,您便能以卓越的效能偵測並掃描輸入文件中的所有型別 BARCODE——一步到位,滿足您的一切需求!此方法支援多種影像格式,例如 JPEG、PNG 和 BMP,以及 PDF 和多幀格式(如 GIF 和 TIFF)。 為提升效能,提供可自訂的設定選項。

為提升讀取速度,您可以建立一個 BarcodeReaderOptions 物件,並設定 Speed 選項以獲得更佳效能。 預設值為 Balanced,但可使用 Faster 選項來跳過某些檢查。

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);
}

您亦可將 ScanMode 設定為 OnlyBasicScan 以優化閱讀體驗。

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);
}

其他設定包含指定要掃描的BarCode格式,這有助於減少不必要的掃描,從而加快處理速度。

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
});

BarCode編寫

若要使用 IronBarcode 繪製 BARCODE,我們會使用 BarcodeWriter 類別。

using IronBarCode;

GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
myBarcode.SaveAsImage("myBarcode.png");

BarCode樣式設定

IronBarcode 提供多種選項,可對 BARCODE 的視覺呈現進行調整。

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");

將 BarCode 匯出為 HTML

IronBarcode 可將 BarCode 匯出為 HTML 文件,或作為 HTML 內容的一部分。

using IronBarCode;

QRCodeWriter.CreateQrCode("https://ironsoftware.com", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPdf("MyQR.pdf");

生成 QR 碼

針對 QR 碼,請使用 QRCodeWriter 類別,該類別提供針對 QR 碼特定功能(如錯誤校正)的額外設定選項。

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");

支援的BarCode格式

IronBarcode 支援多種常見 BarCode 格式的讀取與寫入:

  • QR 碼、Micro QR 碼及矩形 Micro QR(rMQR)
  • 其他二維 BARCODE,例如 AztecData MatrixMaxiCodePDF417
  • 堆疊式線性BarCode,例如 Databar
  • 傳統的一維 BarCode 格式,例如 UPC-AUPC-EEAN-8EAN-13CodabarITFMSIPlessey

為何選擇 IronBarcode?

IronBarcode 提供一個友善且易於使用的 API,讓開發人員能夠在 .NET 環境中讀取和寫入 BARCODE,並針對實際應用情境優化了準確性、精確度與速度。

例如,BarcodeWriter 類別會自動驗證並修正 UPCA 和 UPCE BARCODE 上的"校驗和",並處理數值格式限制。 IronBarcode 協助開發人員為其資料選擇最適合的 BarCode 格式。

此函式庫功能強大,具備自動旋轉與影像去噪等預處理技術,以最大化BARCODE偵測的成功率。

後續進行

為充分發揮 IronBarcode 的功能,我們建議您閱讀本文件區段中的教學指南,並造訪我們的 GitHub 頁面。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備好開始了嗎?

Nuget Downloads 2,422,100版本:2026.9剛剛發布

立即獲取免費

立即獲取 30天試用金鑰

bullet_checked無需信用卡或註冊帳號
bullet_test在生產
環境中進行測試,且不顯示浮水印
bullet_calendar30 天全
功能產品
bullet_support試用期間提供 24/5 技術
支援
立即獲取您的免費30天試用金鑰
不需要信用卡或帳戶建立
C# NuGet程式庫,用於PDF
通過NuGet安裝

版本: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. 在解決方案資源管理器中,右鍵點擊References,管理NuGet包
  2. 選擇瀏覽並搜尋"IronBarCode"
  3. 選擇包並安裝
C# PDF DLL
下載DLL

版本: 2026.9

  1. 下載並解壓IronBarCode至您的Solution目錄中的~/Libs等位置
  2. 在Visual Studio解決方案資源管理器中右鍵點擊References,選擇瀏覽,"IronBarCode.dll"

$999起的授權費用

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費即時演示
Booking Badge

全球數百萬工程師信賴

Iron Software的客戶標誌
獲取您的無義務諮詢
完成下方表單或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
全球數百萬工程師信賴
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立