跳至頁尾內容
與其他組件的比較

Syncfusion Barcode 與 IronBarcode:C# 條碼庫比較

ZXing.Net vs IronBarcode:2026 年選擇 .NET 條碼庫

ZXing.Net 的 BarcodeReader 並非執行緒安全。 在您的應用程式中,每個並行讀取路徑——每個平行 ForEach,每個處理同時請求的非同步控制器行為——都需要自己的讀者實例。 這意味著要為每個實例重複格式配置、每次調用時的 Bitmap 載入和釋放、以及在每次請求上的讀者分配。IronBarcode 的靜態方法可以處理相同的工作,而不需要每次請求進行分配。 執行緒安全只是清單上的一項:沒有原生 PDF 支援,在 Windows 和 Linux 間包碎片化,以及需要具體指定您打算掃描的每個條碼格式——這些都是導致 ZXing.Net 專案長時間積累解決方案的特徵。

瞭解 ZXing.Net

ZXing.Net 是 Google 的 Java ZXing("Zebra Crossing")庫的開源移植,根據 Apache 2.0 許可發佈並由 Michael Jahn 在 GitHub 上維護。 它是 .NET 中下載量最多的開源條碼庫,其悠久的歷史記錄已持續超過十年。 該庫涵蓋多種條碼格式的讀取和寫入,其零成本許可使其可用於各種規模的專案,包括需要 Apache 相容性依賴項的開源產品。

ZXing.Net 的架構反映了其作為 Java 移植的起源。 BarcodeReader 類是一個有狀態的物件:調用 Decode 寫入內部狀態,使得實例無法在執行緒間安全共享。 正確的並發使用需要每個執行緒新建一個讀者,或者使用ThreadLocal<BarcodeReader>池——兩者都將執行緒安全責任交給調用者。 圖像載入也沒有捆綁在核心包中; 相反,ZXing.Net 提供特定平台的綁定包,每個包公開不同的 API 表面。

主要的架構特點包括:

  • Apache 2.0 許可:免費供商用和開源使用,無成本且無需聯絡銷售。
  • 有狀態條碼讀取器:BarcodeReader 實例不是執行緒安全的; 必須為每個執行緒或每個平行操作建立一個新實例。
  • 手動格式指定:調用者必須在每次解碼之前設置reader.Options.PossibleFormats; 未列出的格式將被靜默跳過,無錯誤或警告。
  • 無原生 PDF 支援:該庫僅讀取圖像; PDF 輸入需要一個獨立的 PDF 渲染庫,例如 PdfiumViewer,以在解碼之前將頁面轉換為位圖。
  • 平台綁定碎片化:核心包未提供圖像載入; 獨立的綁定包(ZXing.Net.Bindings.Windows.Compatibility 使用 System.Drawing,ZXing.Net.Bindings.ImageSharp / .V2 / .V3使用 SixLabors.ImageSharp,以及 ZXing.Net.Bindings.SkiaSharpZXing.Net.Bindings.Magick)公開不同的 API,以滿足不同的部署目標。
  • 活躍的社群:在 GitHub 上,問題、拉請求和討論活躍,提供社群級別免費支援。
  • 廣泛的格式覆盖:支援 QR Code、Code 128、Code 39、EAN-13、EAN-8、UPC-A、Data Matrix、PDF 417、Aztec 及其他廣泛使用的符號。

有狀態讀取器架構

ZXing.Net 的 BarcodeReader 需要為每個執行緒或平行操作建立新實例。 以下模式顯示並行處理的最小正確設置:

// ZXing.Net: a new reader instance is created per iteration
Parallel.ForEach(imagePaths, path =>
{
    var reader = new BarcodeReader();
    reader.Options.PossibleFormats = new List<BarcodeFormat>
    {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.EAN_13
    };

    using var bitmap = new Bitmap(path);
    var result = reader.Decode(bitmap);

    if (result != null)
        results[path] = result.Text;
});
// ZXing.Net: a new reader instance is created per iteration
Parallel.ForEach(imagePaths, path =>
{
    var reader = new BarcodeReader();
    reader.Options.PossibleFormats = new List<BarcodeFormat>
    {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.EAN_13
    };

    using var bitmap = new Bitmap(path);
    var result = reader.Decode(bitmap);

    if (result != null)
        results[path] = result.Text;
});
Imports System.Collections.Concurrent
Imports System.Drawing
Imports ZXing

Parallel.ForEach(imagePaths, Sub(path)
    Dim reader = New BarcodeReader()
    reader.Options.PossibleFormats = New List(Of BarcodeFormat) From {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.EAN_13
    }

    Using bitmap As New Bitmap(path)
        Dim result = reader.Decode(bitmap)

        If result IsNot Nothing Then
            results(path) = result.Text
        End If
    End Using
End Sub)
$vbLabelText   $csharpLabel

ThreadLocal<BarcodeReader> 模式通過每執行緒重複使用一個實例來降低每個調用的分配,但增加了釋放的複雜性。 無論如何,在 ZXing.Net 中執行緒安全都是調用者的責任。

理解 IronBarcode

IronBarcode 是 Iron Software 開發的商用 .NET 條碼庫。 它透過無狀態的靜態 API 提供條碼讀取和生成:BarcodeReader.ReadBarcodeWriter.CreateBarcode 是主要的進入點,兩者都不需要實例建立或配置即可使用。 該庫作為單一 NuGet 包發佈,可以在 Windows、Linux、macOS 上以及 Docker 容器中以相同方式執行,而不需要平台特定的綁定包。

IronBarcode 的讀取引擎可以自動檢測超過 50 種條碼符號。 調用者無需指定要尋找的格式; 引擎會將每個圖像與所有支持的格式進行比較,並返回找到的每一個條碼。 對於需要平衡掃描速度和全面性的應用,ReadingSpeed 枚舉(ExtremeDetail)提供了控制,而不需要格式枚舉。 該庫還包括原生 PDF 支援,可以直接從所有頁面的 PDF 文件中讀取條碼,而無需獨立的 PDF 渲染庫。

主要特徵包括:

  • 商用許可:需要付費許可金鑰; 試用模式可供評估使用。
  • 無狀態靜態 API:BarcodeReader.ReadBarcodeWriter.CreateBarcode 是執行緒安全的靜態方法; 無需管理實例。
  • 自動格式檢測:可檢測所有 50 多個支持的條碼格式,無需格式清單;調用者可以調整速度而不是格式範圍。
  • 原生 PDF 支援:BarcodeReader.Read 可直接接受 PDF 檔案路徑,處理所有頁面而不需外部 PDF 庫。
  • 單一跨平台包:一個 NuGet 包可在 Windows、Linux、macOS 和 Docker 上以相同 API 表面執行。
  • 簡潔生成 API:BarcodeWriter.CreateBarcode 返回一個 GeneratedBarcode 物件,內建輸出方法包括 ToPngBinaryDataToStream
  • 商業支援:付費許可包含對 Iron Software 支援團隊的支援存取,並有服務級別承諾。

功能比較

下表突出了 ZXing.Net 和IronBarcode之間的基本差異:

功能 ZXing.Net IronBarcode
許可 Apache 2.0(免費) 商業
執行緒安全 非執行緒安全——每個執行緒需要新實例 執行緒安全靜態 API
格式檢測 手動——需要 PossibleFormats 清單 自動——50 多種格式
PDF 讀取 否——需要 PdfiumViewer 或類似工具 原生——單一方法調用
平台支援 每個平台有單獨的綁定包 單一包,所有平台
條碼生成 返回 Bitmap,需要手動保存 具有內建輸出的簡化 API
定價 免費 從 $749 起(Lite)/ $1,499(Plus)

詳細功能比較

功能 ZXing.Net IronBarcode
讀取
執行緒安全讀取 否——每個執行緒需要實例 是——靜態無狀態 API
自動格式檢測 否——需要 PossibleFormats 是——所有格式自動檢測
每個圖像多個條碼 是——DecodeMultiple 是——預設行為
PDF 條碼讀取 否——需要外部庫 是——原生
損壞條碼恢復 TryHarder 標誌 ML 驅動的圖像校正
速度/準確性調整 格式列表縮減 ReadingSpeed 枚舉
生成
Code 128 / Code 39
QR Code
帶有標誌的 QR Code
QR Code 顏色定制
輸出為 PNG/JPEG/PDF 通過 System.Drawing 手動 內建輸出方法
簡潔生成鏈
平台和部署
Windows (System.Drawing) 是——ZXing.Net.Bindings.Windows.Compatibility
Linux / Docker 是——ZXing.Net.Bindings.ImageSharp / .V2 / .V3 (不同 API) 是——相同 API
macOS 是——ZXing.Net.Bindings.ImageSharp / .V2 / .V3
Docker 額外依賴 可能需要 libgdiplus None
單一 NuGet 套件 否——核心 + 綁定 + 可選的 ImageSharp
許可與支援
許可型別 Apache 2.0 商業
成本 免費 從 $749 起
社群支援 GitHub 問題,活躍社群
商業 SLA 支援
對開源友好

執行緒安全與並行處理

執行緒安全是這兩個庫之間最重要的運行差異,它影響的項目數量可能比文件警告所暗示的多。

ZXing.Net 方法

ZXing.Net 的 BarcodeReader 是一個有狀態的物件。 當調用 Decode 時,內部狀態被寫入。 如果兩個執行緒共享相同的實例,這些寫入會競賽。 結果是非確定性的:您可能會得到來自不同圖像的結果,條碼存在的地方得到 null ,或者出現異常。 正確的方法是為每個執行緒建立一個讀者——這意味著每個並行或非同步路徑都會分配一個讀者,配置它,使用一次,然後丟棄它:

// ZXing.Net: one reader instance per parallel operation
Parallel.ForEach(imagePaths, path =>
{
    var reader = new BarcodeReader();
    reader.Options.PossibleFormats = new List<BarcodeFormat>
    {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.EAN_13
    };

    using var bitmap = new Bitmap(path);
    var result = reader.Decode(bitmap);

    if (result != null)
        results[path] = result.Text;
});
// ZXing.Net: one reader instance per parallel operation
Parallel.ForEach(imagePaths, path =>
{
    var reader = new BarcodeReader();
    reader.Options.PossibleFormats = new List<BarcodeFormat>
    {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.EAN_13
    };

    using var bitmap = new Bitmap(path);
    var result = reader.Decode(bitmap);

    if (result != null)
        results[path] = result.Text;
});
Imports System.Collections.Concurrent
Imports System.Drawing
Imports ZXing

Parallel.ForEach(imagePaths, Sub(path)
    Dim reader As New BarcodeReader()
    reader.Options.PossibleFormats = New List(Of BarcodeFormat) From {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.EAN_13
    }

    Using bitmap As New Bitmap(path)
        Dim result = reader.Decode(bitmap)

        If result IsNot Nothing Then
            results(path) = result.Text
        End If
    End Using
End Sub)
$vbLabelText   $csharpLabel

ThreadLocal<BarcodeReader> 模式通過每執行緒重複使用一個讀者來降低每次調用的分配,但增加了釋放的複雜性,並且仍需要每個實例的格式配置。

IronBarcode 方法

IronBarcode 的 BarcodeReader.Read 是一個無狀態靜態方法。 沒有實例需要共享,沒有實例需要隔離,也沒有配置狀態需要保護。 相同的調用可以在任何數量的並行執行緒中安全進行:

// IronBarcode: static method — no instance management
var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true,
    MaxParallelThreads = 4
};

Parallel.ForEach(imagePaths, path =>
{
    var result = BarcodeReader.Read(path, options).FirstOrDefault();
    if (result != null)
        results[path] = result.Value;
});
// IronBarcode: static method — no instance management
var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true,
    MaxParallelThreads = 4
};

Parallel.ForEach(imagePaths, path =>
{
    var result = BarcodeReader.Read(path, options).FirstOrDefault();
    if (result != null)
        results[path] = result.Value;
});
Imports IronBarcode

Dim options As New BarcodeReaderOptions With {
    .Speed = ReadingSpeed.Balanced,
    .ExpectMultipleBarcodes = True,
    .MaxParallelThreads = 4
}

Parallel.ForEach(imagePaths, Sub(path)
    Dim result = BarcodeReader.Read(path, options).FirstOrDefault()
    If result IsNot Nothing Then
        results(path) = result.Value
    End If
End Sub)
$vbLabelText   $csharpLabel

IronBarcode 的非同步和多執行緒條碼讀取文件解釋了內部執行緒池模型。 MaxParallelThreads 屬性控制並行度,無需外部協調。

格式檢測

格式檢測策略是這兩個庫之間的第二個重要運行差異。

ZXing.Net 方法

ZXing.Net 要求在每次解碼之前填充reader.Options.PossibleFormats。 如果沒有列出條碼格式,則不會檢測到——沒有錯誤,沒有警告,也沒有部分結果:

// ZXing.Net: PossibleFormats list controls which symbologies are decoded
var reader = new BarcodeReader();
reader.Options.PossibleFormats = new List<BarcodeFormat>
{
    BarcodeFormat.QR_CODE,
    BarcodeFormat.CODE_128,
    BarcodeFormat.CODE_39,
    BarcodeFormat.EAN_13,
    BarcodeFormat.EAN_8,
    BarcodeFormat.UPC_A,
    BarcodeFormat.DATA_MATRIX,
    BarcodeFormat.PDF_417
};
reader.Options.TryHarder = true;

using var bitmap = new Bitmap(imagePath);
var results = reader.DecodeMultiple(bitmap);
// ZXing.Net: PossibleFormats list controls which symbologies are decoded
var reader = new BarcodeReader();
reader.Options.PossibleFormats = new List<BarcodeFormat>
{
    BarcodeFormat.QR_CODE,
    BarcodeFormat.CODE_128,
    BarcodeFormat.CODE_39,
    BarcodeFormat.EAN_13,
    BarcodeFormat.EAN_8,
    BarcodeFormat.UPC_A,
    BarcodeFormat.DATA_MATRIX,
    BarcodeFormat.PDF_417
};
reader.Options.TryHarder = true;

using var bitmap = new Bitmap(imagePath);
var results = reader.DecodeMultiple(bitmap);
Imports ZXing
Imports ZXing.Common

' ZXing.Net: PossibleFormats list controls which symbologies are decoded
Dim reader As New BarcodeReader()
reader.Options.PossibleFormats = New List(Of BarcodeFormat) From {
    BarcodeFormat.QR_CODE,
    BarcodeFormat.CODE_128,
    BarcodeFormat.CODE_39,
    BarcodeFormat.EAN_13,
    BarcodeFormat.EAN_8,
    BarcodeFormat.UPC_A,
    BarcodeFormat.DATA_MATRIX,
    BarcodeFormat.PDF_417
}
reader.Options.TryHarder = True

Using bitmap As New Bitmap(imagePath)
    Dim results = reader.DecodeMultiple(bitmap)
End Using
$vbLabelText   $csharpLabel

如果列出了所有格式以避免遺漏,性能會下降。 如果僅列出預期格式,當圖像來自外部來源時,靜默遺漏成為風險。 ZXing.Net 沒有機制報告它在未列出的格式中找到了條碼。

IronBarcode 方法

IronBarcode 自動檢測所有 50 多個支持的格式。 不需要或接受格式列表:

// IronBarcode: automatic detection across all supported formats
var results = BarcodeReader.Read(imagePath);
foreach (var barcode in results)
{
    Console.WriteLine($"{barcode.Value} ({barcode.Format})");
}
// IronBarcode: automatic detection across all supported formats
var results = BarcodeReader.Read(imagePath);
foreach (var barcode in results)
{
    Console.WriteLine($"{barcode.Value} ({barcode.Format})");
}
Imports IronBarcode

' IronBarcode: automatic detection across all supported formats
Dim results = BarcodeReader.Read(imagePath)
For Each barcode In results
    Console.WriteLine($"{barcode.Value} ({barcode.Format})")
Next
$vbLabelText   $csharpLabel

對於調整讀取速度和檢測全面性的應用,IronBarcode 不需要格式枚舉,直接輸出一個Faster, Balanced, Detailed, ExtremeDetail。 速度調整影響引擎如何積極地處理每個圖像,而不是考慮哪種格式。

PDF 文件支持

PDF 讀取是 ZXing.Net 中的一個硬邊界:該庫沒有任何形式的 PDF 支持。

ZXing.Net 方法

當條碼嵌入在 PDF 中到達時,ZXing.Net 需要一個外部 PDF 渲染庫。 最常見的解決方案使用 PdfiumViewer,這會新增大約 20 MB 的原生二進位檔案,以及調用者必須實現和維護的頁面渲染迴圈:

// ZXing.Net: PDF input is handled by PdfiumViewer with a per-page render loop
using var pdfDocument = PdfDocument.Load(pdfPath);

var reader = new BarcodeReader();
reader.Options.PossibleFormats = new List<BarcodeFormat>
{
    BarcodeFormat.QR_CODE,
    BarcodeFormat.CODE_128,
    BarcodeFormat.PDF_417
};

for (int i = 0; i < pdfDocument.PageCount; i++)
{
    string tempPath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.png");
    try
    {
        using var pageImage = pdfDocument.Render(i, 200, 200, PdfRenderFlags.CorrectFromDpi);
        pageImage.Save(tempPath, ImageFormat.Png);

        using var bitmap = new Bitmap(tempPath);
        var decoded = reader.DecodeMultiple(bitmap);
        if (decoded != null)
            results.AddRange(decoded.Select(d => d.Text));
    }
    finally
    {
        File.Delete(tempPath);
    }
}
// ZXing.Net: PDF input is handled by PdfiumViewer with a per-page render loop
using var pdfDocument = PdfDocument.Load(pdfPath);

var reader = new BarcodeReader();
reader.Options.PossibleFormats = new List<BarcodeFormat>
{
    BarcodeFormat.QR_CODE,
    BarcodeFormat.CODE_128,
    BarcodeFormat.PDF_417
};

for (int i = 0; i < pdfDocument.PageCount; i++)
{
    string tempPath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.png");
    try
    {
        using var pageImage = pdfDocument.Render(i, 200, 200, PdfRenderFlags.CorrectFromDpi);
        pageImage.Save(tempPath, ImageFormat.Png);

        using var bitmap = new Bitmap(tempPath);
        var decoded = reader.DecodeMultiple(bitmap);
        if (decoded != null)
            results.AddRange(decoded.Select(d => d.Text));
    }
    finally
    {
        File.Delete(tempPath);
    }
}
Imports System.IO
Imports System.Drawing
Imports PdfiumViewer
Imports ZXing
Imports ZXing.Common

' ZXing.Net: PDF input is handled by PdfiumViewer with a per-page render loop
Using pdfDocument As PdfDocument = PdfDocument.Load(pdfPath)

    Dim reader As New BarcodeReader()
    reader.Options.PossibleFormats = New List(Of BarcodeFormat) From {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.PDF_417
    }

    For i As Integer = 0 To pdfDocument.PageCount - 1
        Dim tempPath As String = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.png")
        Try
            Using pageImage As Image = pdfDocument.Render(i, 200, 200, PdfRenderFlags.CorrectFromDpi)
                pageImage.Save(tempPath, Imaging.ImageFormat.Png)

                Using bitmap As New Bitmap(tempPath)
                    Dim decoded = reader.DecodeMultiple(bitmap)
                    If decoded IsNot Nothing Then
                        results.AddRange(decoded.Select(Function(d) d.Text))
                    End If
                End Using
            End Using
        Finally
            File.Delete(tempPath)
        End Try
    Next
End Using
$vbLabelText   $csharpLabel

此模式存在實際的故障模式:DPI 配置錯誤導致靜默遺漏,臨時檔案權限在鎖定環境中失敗,PdfiumViewer 原生庫需要單獨的部署管理,並且設置不適用於 Linux,除非進行額外配置。

IronBarcode 方法

IronBarcode 直接讀取 PDF 中的條碼 ——所有頁面,所有格式,無需外部依賴。 相同的 BarcodeReader.Read 調用直接接受 PDF 路徑:

// IronBarcode: one call processes every page of the PDF
var results = BarcodeReader.Read("invoice.pdf");
foreach (var barcode in results)
    Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Value}");
// IronBarcode: one call processes every page of the PDF
var results = BarcodeReader.Read("invoice.pdf");
foreach (var barcode in results)
    Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Value}");
Imports IronBarcode

' IronBarcode: one call processes every page of the PDF
Dim results = BarcodeReader.Read("invoice.pdf")
For Each barcode In results
    Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Value}")
Next
$vbLabelText   $csharpLabel

沒有頁面枚舉,沒有 DPI 配置,沒有臨時檔案,也不需要單獨的庫與應用一起部署。

平台綁定和部署

ZXing.Net 的圖像處理分布在平臺特定綁定包中,每個包都有不同的 API 表面。

ZXing.Net 方法

核心ZXing.Net包提供解碼邏輯但不提供圖像載入。 調用者必須根據他們的部署目標選擇綁定:

環境 套餐 注意事項
Windows 桌面 / WPF ZXing.Net.Bindings.Windows.Compatibility 使用 System.Drawing——Windows友好; 在 Linux 上需要 libgdiplus
Linux / Docker / 跨平台 ZXing.Net.Bindings.ImageSharp / .V2 / .V3 不同的 API 表面; 新增 SixLabors.ImageSharp 依賴(V2/V3 跟踪 ImageSharp 主要版本)
macOS ZXing.Net.Bindings.ImageSharp / .V2 / .V3 路徑與 Linux 相同

實際結果是,使用 System.Drawing.Bitmap 的 Windows 程式碼無法在 Linux 上編譯或運行。 集裝箱化需要切換綁定包並重新編寫圖像載入程式碼:

// Windows binding path — uses System.Drawing
using ZXing.Windows.Compatibility;
using System.Drawing;

var reader = new BarcodeReader();
using var bitmap = new Bitmap(imagePath);
var result = reader.Decode(bitmap);
// Windows binding path — uses System.Drawing
using ZXing.Windows.Compatibility;
using System.Drawing;

var reader = new BarcodeReader();
using var bitmap = new Bitmap(imagePath);
var result = reader.Decode(bitmap);
Imports ZXing.Windows.Compatibility
Imports System.Drawing

Dim reader As New BarcodeReader()
Using bitmap As New Bitmap(imagePath)
    Dim result = reader.Decode(bitmap)
End Using
$vbLabelText   $csharpLabel
// Cross-platform path — different package, different API
using ZXing.ImageSharp;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

var reader = new BarcodeReader<Rgba32>();
using var image = Image.Load<Rgba32>(imagePath);
var result = reader.Decode(image);
// Cross-platform path — different package, different API
using ZXing.ImageSharp;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

var reader = new BarcodeReader<Rgba32>();
using var image = Image.Load<Rgba32>(imagePath);
var result = reader.Decode(image);
Imports ZXing.ImageSharp
Imports SixLabors.ImageSharp
Imports SixLabors.ImageSharp.PixelFormats

Dim reader As New BarcodeReader(Of Rgba32)()
Using image As Image(Of Rgba32) = Image.Load(Of Rgba32)(imagePath)
    Dim result = reader.Decode(image)
End Using
$vbLabelText   $csharpLabel

在 Linux 主機上使用 Windows 綁定還需要在 Docker 圖像中包含 libgdiplus,增加大約 50 MB 的容器。

IronBarcode 方法

IronBarcode 為所有平臺發送一個包。 相同的 BarcodeReader.Read(path) 調用在 Windows、Linux、macOS 和 Docker 容器中相同的編譯和運行。 不需要綁定包,不需要平臺條件,也不需要額外的系統依賴。 對於將 .NET 應用程式容器化的團隊,IronBarcode Docker 和 Linux 設置指南詳細介紹了單包部署模式。

生成 API

兩個庫都能生成條碼,但 API 反映了不同的設計方法。

ZXing.Net 方法

ZXing.Net 的 BarcodeWriter 類建立一個寫入物件,接受編碼選項,調用 Write,並返回 Bitmap,調用者必須使用 System.Drawing.Imaging 手動保存:

// ZXing.Net: create writer, set options, call Write, save Bitmap
using ZXing;
using ZXing.Common;
using ZXing.Windows.Compatibility;
using System.Drawing.Imaging;

var writer = new BarcodeWriter
{
    Format = BarcodeFormat.CODE_128,
    Options = new EncodingOptions
    {
        Width = 300,
        Height = 100,
        Margin = 10
    }
};

using var bitmap = writer.Write("PRODUCT-001");
bitmap.Save("output.png", ImageFormat.Png);
// ZXing.Net: create writer, set options, call Write, save Bitmap
using ZXing;
using ZXing.Common;
using ZXing.Windows.Compatibility;
using System.Drawing.Imaging;

var writer = new BarcodeWriter
{
    Format = BarcodeFormat.CODE_128,
    Options = new EncodingOptions
    {
        Width = 300,
        Height = 100,
        Margin = 10
    }
};

using var bitmap = writer.Write("PRODUCT-001");
bitmap.Save("output.png", ImageFormat.Png);
Imports ZXing
Imports ZXing.Common
Imports ZXing.Windows.Compatibility
Imports System.Drawing.Imaging

Dim writer As New BarcodeWriter With {
    .Format = BarcodeFormat.CODE_128,
    .Options = New EncodingOptions With {
        .Width = 300,
        .Height = 100,
        .Margin = 10
    }
}

Using bitmap = writer.Write("PRODUCT-001")
    bitmap.Save("output.png", ImageFormat.Png)
End Using
$vbLabelText   $csharpLabel

保存為 PNG 或 JPEG 以外的格式、保存為 PDF 或為 HTTP 響應生成二進製輸出時都需要附加的 System.Drawing 管線,調用者實施。

IronBarcode 方法

IronBarcode 的 BarcodeWriter.CreateBarcode 返回一個 GeneratedBarcode 物件,該物件通過一個流暢的鏈提供內建的輸出方法:

// IronBarcode: create and save in one fluent chain
BarcodeWriter.CreateBarcode("PRODUCT-001", BarcodeEncoding.Code128)
    .ResizeTo(300, 100)
    .SaveAsPng("output.png");
// IronBarcode: create and save in one fluent chain
BarcodeWriter.CreateBarcode("PRODUCT-001", BarcodeEncoding.Code128)
    .ResizeTo(300, 100)
    .SaveAsPng("output.png");
Imports IronBarCode

' IronBarcode: create and save in one fluent chain
BarcodeWriter.CreateBarcode("PRODUCT-001", BarcodeEncoding.Code128) _
    .ResizeTo(300, 100) _
    .SaveAsPng("output.png")
$vbLabelText   $csharpLabel

GeneratedBarcode 物件還公開 .ToStream().SaveAsPdf()——這些都是 ZXing.Net 要求調用者使用 System.Drawing 自己實現的輸出目標。

API 映射參考

ZXing.Net IronBarcode 注意事項
new BarcodeReader() 靜態——無需實例 BarcodeReader.Read(...) 是靜態呼叫
`reader.Options.PossibleFormats = new List { ... } 不需要 自動檢測涵蓋所有格式
reader.Options.TryHarder = true Speed = ReadingSpeed.Balanced 通過 BarcodeReaderOptions 調整準確性
reader.Decode(bitmap) BarcodeReader.Read(imagePath) 直接傳遞路徑——不需要 Bitmap
reader.DecodeMultiple(bitmap) BarcodeReader.Read(imagePath) 總是返回一個集合
result.Text result.Value 屬性已重命名
result.BarcodeFormat result.Format 屬性已重命名
BarcodeFormat.QR_CODE BarcodeEncoding.QRCode 枚舉命名規範變更
BarcodeFormat.CODE_128 BarcodeEncoding.Code128 枚舉命名規範變更
BarcodeFormat.EAN_13 BarcodeEncoding.EAN13 枚舉命名規範變更
new BarcodeWriter { Format = BarcodeFormat.CODE_128, Options = new EncodingOptions { ... } } BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128) 靜態工廠方法
writer.Write(data) 返回 Bitmap .SaveAsPng(path) / .ToPngBinaryData() GeneratedBarcode 上的內建輸出方法
無 PDF 支持——需要 PdfiumViewer BarcodeReader.Read("doc.pdf") 原生 PDF 支持
無執行緒安全 執行緒安全靜態 API 無需實例管理

當團隊考慮從 ZXing.Net 移動到IronBarcode時

幾種情況促使開發團隊評估IronBarcode作為 ZXing.Net 的替代品。

並發和高吞吐量處理

一個在單執行緒控制台應用中正常工作的 ZXing.Net 整合,當相同的程式碼移動到處理並發請求的 ASP.NET Core 控制器中,或者移動到批次平行處理的後台工作時,可能會表現出非確定性行為。 ZXing.Net 所需的每個執行緒實例模式意味著每次請求或並行任務都會分配一個完整的讀取器物件及其配置的解碼器集,使用一次,然後將其丟棄。 隨著請求量的增長,這種分配壓力開始變得可測。 達到這一點的團隊——特別是那些在物流、倉儲或文件處理中運行高吞吐量掃描管線的團隊——通常會尋找一個執行緒模型不會將此開銷施加給每個調用者的庫。

混合格式文件掃描

接受第三方文件的應用程式經常會遇到條碼格式,而這些格式在配置格式列表時未預見到。 為 Code 128 構建的運輸整合從使用 QR 欄程式碼的合作夥伴處收到運送。 配置為 PDF 417 的醫療紀錄系統遇到新裝置供應商的 Data Matrix 符號。 在 ZXing.Net 中,每個這些案例都會生成一個靜默空值,而不是解碼錯誤,這意味著在下游處理失敗之前遺漏可能無法顯現。 那些曾被靜默格式撲滅的團隊——尤其是在未命中的條碼有業務後果的上下文中——開始衡量格式列表維護的成本,並與檢測格式自動執行的庫進行平衡。

PDF 條碼提取

許多業務文件以 PDF 形式到來:發票、運單、病人紀錄、合規證書。 ZXing.Net 無法直接讀取這些。 需要從 PDF 提取條碼的團隊最終在 ZXing.Net 之上構建和維護一個渲染管道——選擇一個 PDF 庫,管理其原生依賴,實施頁面渲染迴圈,處理 DPI 配置,編寫臨時文件的清理邏輯。 該基礎設施程式碼不是條碼邏輯; 它只是為了彌合 ZXing.Net 接受的位圖和實際業務文件是 PDF 之間的鴻溝。 發現自己正在維護此橋樑的團隊——特別是當 PDF 庫本身具有其自己的許可、部署和平台考量因素時——通常偏向單一庫來處理完整的輸入表面。

減少綁定複雜性

在 Windows 上開始專案並部署到 Linux 或 Docker 的專案直接遇到 ZXing.Net 的綁定碎片化:Windows 綁定包使用的 API 與跨平台 ImageSharp 綁定的不同,切換它們需要更改 NuGet 引用和圖像載入程式碼。 那麼將其 .NET 應用程式做為慣例容器化的團隊,或者在開發人員機器 (Windows 或 macOS) 和 產品伺服器 (Linux) 上運行相同程式碼庫的團隊,會發現為圖像載入維護兩個程式碼路徑增加了每次未來更改掃描層的摩擦。

常見遷移考量

過渡從 ZXing.Net 到IronBarcode的團隊應該為這些特定的技術變更做好計畫。

刪除 BarcodeReader 實例化

程式碼庫中的每個 new BarcodeReader() 調用在遷移期間被移除。 實例化模式——讀取器建立、格式配置、圖像載入、解碼調用——崩解成為一個靜態方法呼叫。 進口using IronBarCode;

可能的格式配置刪除

在每個調用站點,reader.Options.PossibleFormats 賦值塊被刪除。IronBarcode自動執行格式檢測,並且不接受格式限制列表。 TryHarder 標誌被 ReadingSpeed 屬性替代在BarcodeReaderOptions上,以控制檢測努力而不縮小格式範圍。

綁定包清理

遷移移除了 ZXing.Net.Bindings.Windows.Compatibility、任何 ZXing.Net.Bindings.ImageSharp 變體 (.V2 / .V3) 和任何 PdfiumViewer 為了支持 PDF 讀取的包。 如果在 Dockerfile 中新增了 libgdiplus 以支持 System.Drawing 通過 Linux 上的 Windows 綁定,那麼該行也被移除。IronBarcode在 Docker 圖像中不需要平台特定的依賴項。

追加的IronBarcode功能

除了上面比較部分涵蓋的功能,IronBarcode 提供:

.NET 相容及未來準備

IronBarcode 目標 .NET Standard 2.0 及以上版本,提供與 .NET Framework 4.6.2+、.NET Core 3.1、.NET 5、.NET 6、.NET 7、.NET 8 和 .NET 9 的相容性。庫會定期根據 Microsoft 的 .NET 發佈週期進行更新,確保與 .NET 10 相容的內容將在發佈時或接近發佈時可用。 ZXing.Net 也通過其 NuGet 包目標支持廣泛的 .NET 相容性,從這個角度來看,兩個庫都適合現代 .NET 專案。

結論

ZXing.Net 和IronBarcode代表了條碼庫設計的不同哲學。 ZXing.Net 是一個有狀態、基於實例的庫,將執行緒責任、格式規範和 PDF 橋接完全委託給調用者。IronBarcode是一個無狀態、靜態 API 庫,內部化執行緒,自動檢測格式,並且原生處理 PDF 輸入。 這一差異的實際結果是 ZXing.Net 程式碼在並發或文件處理上下文中往往會積累基礎設施——每執行緒的實例模式、格式列表、PDF 渲染管線和平台特定的綁定分支——而IronBarcode對於相同場景的程式碼不需要任何這些周圍的結構。

ZXing.Net 是對於沒有成本要求的專案的一個堅實選擇。 其 Apache 2.0 許可使其與開源專案以及偏好免費依賴的商業產品相容。 對於受控環境——已知的條碼格式,清晰的圖像,單執行緒或輕量並發處理,它表現穩定。 其活躍的 GitHub 社群為問題提供了及時響應,其格式覆蓋範圍相當於商業替代品。 對於那些條件成立的應用,ZXing.Net 的成本優勢是真實的,其技術限制是可管理的。

IronBarcode 解決了 ZXing.Net 設計限制成為運營成本的情景:並發 Web API;其每次請求實例分配是可測量的,文件管道中 PDF 輸入是常態而不是例外的,當混合格式掃描時靜默遺漏會帶來商業風險,跨平台的部署中兩個綁定包意味著兩條程式碼路。 對於那些上下文,該庫的商業許可買下了一個不施加實例管理負擔的執行緒模型,無需維護的格式檢測,與不需要第二個庫的 PDF 支援。

決策取決於專案的需求。 一個單格式原型、開源掃描器或成本是約束條件的低容量工具——這些是適合選擇 ZXing.Net 的用例。 將文件從外部來源處理到多執行緒環境的生產 Web API——這是IronBarcode設計假設與操作現實吻合的地方。 對於兩種庫在檢測率和真實世界掃描情景中的比較,ZXing.Net vsIronBarcode條碼掃描器比較提供了更多的分析。

常見問題

什麼是 ZXing.Net?

ZXing.Net 是一個 .NET 條碼程式庫,用於在 C# 應用程式中生成和讀取條碼。這是開發人員在選擇 .NET 專案的條碼解決方案時考慮的幾個替代方案之一。

ZXing.Net 和 IronBarcode 之間的主要差異是什麼?

IronBarcode 使用靜態的無狀態 API,不需要實例管理,而 ZXing.Net 通常需要在使用前建立和配置實例。IronBarcode 也提供原生 PDF 支援、自動格式檢測及跨所有環境的單鍵授權。

IronBarcode 比 ZXing.Net 更容易授權嗎?

IronBarcode使用一個覆蓋開發和生產部署的單一授權金鑰。相比於將SDK金鑰與運行時金鑰分開的授權系統,這簡化了CI/CD管道和Docker配置。

IronBarcode 是否支持所有 ZXing.Net 支持的條碼格式?

IronBarcode支持超過30種條碼符號,包括QR Code、Code 128、Code 39、DataMatrix、PDF417、Aztec、EAN-13、UPC-A、GS1等。格式自動檢測意味著不需要顯式的格式枚舉。

IronBarcode支持原生PDF條碼讀取嗎?

是的。IronBarcode可以直接從PDF文件中讀取條碼,使用BarcodeReader.Read("document.pdf"),無需單獨的PDF渲染程式庫。每頁結果包括頁碼、條碼格式、值和置信分數。

IronBarcode 如何處理批量處理與 ZXing.Net 相比?

IronBarcode的靜態方法無狀態且天然執行緒安全,可以直接使用Parallel.ForEach而無需每個執行緒的實例管理。任何價格級別下都沒有吞吐量上限。

IronBarcode支持哪些.NET版本?

IronBarcode支持.NET Framework 4.6.2+、.NET Core 3.1,以及.NET 5、6、7、8和9,單一NuGet包。平台目標包括Windows x64/x86、Linux x64和macOS x64/ARM。

如何在.NET專案中安裝IronBarcode?

通過NuGet安裝IronBarcode:在Package Manager Console中運行 'Install-Package IronBarCode',或在CLI中運行 'dotnet add package IronBarCode'。不需要額外的SDK安裝程式或運行時文件。

是否可以在購買前評估 IronBarcode 而不是 ZXing.Net?

可以。IronBarcode的試用模式返回完整解碼的條碼值——只有生成的輸出圖像上有水印。您可以在自己的文件上評估讀取準確性,然後再決定購買。

ZXing.Net 和 IronBarcode 之間的價格差異是什麼?

IronBarcode起價為$749,為單開發者所適用的永久授權,覆蓋開發和生產。價格詳情和批量選項可在IronBarcode授權頁面獲得。無需單獨的運行時授權。

從 ZXing.Net 遷移到 IronBarcode 是否簡單?

從 ZXing.Net 遷移到 IronBarcode 主要涉及將基於實例的 API 呼叫替換為 IronBarcode 的靜態方法,去除授權樣板及更新結果屬性名稱。大多數遷移涉及減少程式碼而不是增加。

IronBarcode可以生成帶有Logo的QR碼嗎?

可以。QRCodeWriter.CreateQrCode().AddBrandLogo("logo.png") 可以原生嵌入品牌圖像進QR碼,並可配置錯誤更正。也支持通過ChangeBarCodeColor() 生成彩色QR碼。

Curtis Chau
技術作家

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

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話