跳至頁尾內容
影片

IronBarcode 和 ZXing Net 庫的比较

從Scandit SDK遷移到IronBarcode

Scandit SDK是一個構建用於即時移動條碼檢測的相機掃描平台。 IronBarcode是一個針對.NET的伺服器端及基於文件的條碼處理程式庫。 這兩個程式庫服務於不同的主要用例,從一個遷移到另一個僅在特定情況下相關。

本指南涵蓋了使用Scandit的.NET套件處理文件、PDF或伺服器端文件流的團隊的遷移路徑——在這些場景中,Scandit的相機管道架構帶來阻力而非價值。 如果您的核心需求是用移動相機指向實體物件並接收帶有增強現實疊加的即時反饋,Scandit仍然是適當的工具,此指南不適用。 如果您的需求是從上傳的圖片中讀取條碼,從PDF文件中提取條碼資料,或在ASP.NET Core、Azure Functions、Docker容器或背景處理服務中運行條碼檢測,本指南提供一個完整的遷移路徑。

為什麼要從Scandit SDK遷移

相機管道開銷:每次Scandit整合都以相同的初始化序列開始,無論部署環境中是否存在相機:構建Camera實例、將其分配為幀源、將相機轉換為活動狀態並啟用條碼捕獲。 這一初始化存在是因為Scandit處理即時影片幀。 對於伺服器端文件處理,這一序列沒有任何好處,並引入了在目標環境中不存在的狀態複雜性——在Docker容器中沒有相機,在Azure Function中沒有幀源。

沒有公開的價格:Scandit不公開價格。 SparkScan、MatrixScan、ID Scanning、增強現實疊加和解析器是需分別詢價的單獨產品。 在進入銷售迴圈之前,無法完成預算提案、供應商比較或成本效益分析。 IronBarcode公佈了其價格——749美元、1499美元或2999美元的一次性永久購買——因此在開始寫程式碼之前就知道了這個數字。

強制條碼型別聲明:Scandit要求在掃描會話開始前顯式啟用每一種條碼格式。 在即時相機掃描中,這是一種性能優化——限制條碼型別減少了每個幀的處理開銷。 在基於文件的文件處理中,當接收的文件可能來自任何供應商或合作夥伴並攜帶任何條碼格式時,強制格式聲明成為一個限制。 枚舉每種可能的條碼型別既沒有性能優勢; 在圖書館頂層編寫格式猜測邏輯增加了工程負擔。

不支持PDF:在Scandit的API中沒有直接等價的BarcodeReader.Read("invoice.pdf")。 從PDF文件中提取條碼需要使用單獨的程式庫將每一頁渲染為光柵圖像,然後將這些渲染的圖像通過相機模擬管道。這種方法在文件處理工作流中需要額外的依賴性,額外的授權,以及巨大的工程努力。

基本問題

Scandit需要在任何條碼工作開始之前運行相機。 IronBarcode只需要一個文件路徑:

// Scandit SDK: mandatory camera pipeline before first barcode read
var dataCaptureContext = DataCaptureContext.ForLicenseKey("YOUR-SCANDIT-LICENSE");
var settings = BarcodeCaptureSettings.Create();
settings.EnableSymbologies(new HashSet<Symbology>
{
    Symbology.Ean13Upca,
    Symbology.Ean8,
    Symbology.Code128,
    Symbology.QrCode
});
var barcodeCapture = BarcodeCapture.Create(dataCaptureContext, settings);
var camera = Camera.GetDefaultCamera();
await dataCaptureContext.SetFrameSourceAsync(camera);
await camera.SwitchToDesiredStateAsync(FrameSourceState.On);
barcodeCapture.IsEnabled = true;
// Results arrive later via BarcodeScanned event callback
// Scandit SDK: mandatory camera pipeline before first barcode read
var dataCaptureContext = DataCaptureContext.ForLicenseKey("YOUR-SCANDIT-LICENSE");
var settings = BarcodeCaptureSettings.Create();
settings.EnableSymbologies(new HashSet<Symbology>
{
    Symbology.Ean13Upca,
    Symbology.Ean8,
    Symbology.Code128,
    Symbology.QrCode
});
var barcodeCapture = BarcodeCapture.Create(dataCaptureContext, settings);
var camera = Camera.GetDefaultCamera();
await dataCaptureContext.SetFrameSourceAsync(camera);
await camera.SwitchToDesiredStateAsync(FrameSourceState.On);
barcodeCapture.IsEnabled = true;
// Results arrive later via BarcodeScanned event callback
Imports Scandit.DataCapture.Core
Imports Scandit.DataCapture.Barcode
Imports System.Collections.Generic

' Scandit SDK: mandatory camera pipeline before first barcode read
Dim dataCaptureContext = DataCaptureContext.ForLicenseKey("YOUR-SCANDIT-LICENSE")
Dim settings = BarcodeCaptureSettings.Create()
settings.EnableSymbologies(New HashSet(Of Symbology) From {
    Symbology.Ean13Upca,
    Symbology.Ean8,
    Symbology.Code128,
    Symbology.QrCode
})
Dim barcodeCapture = BarcodeCapture.Create(dataCaptureContext, settings)
Dim camera = Camera.GetDefaultCamera()
Await dataCaptureContext.SetFrameSourceAsync(camera)
Await camera.SwitchToDesiredStateAsync(FrameSourceState.On)
barcodeCapture.IsEnabled = True
' Results arrive later via BarcodeScanned event callback
$vbLabelText   $csharpLabel
// IronBarcode: direct file reading
// NuGet: dotnet add package IronBarcode
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
var results = BarcodeReader.Read("barcode.png");
foreach (var result in results)
    Console.WriteLine($"{result.Value} ({result.Format})");
// IronBarcode: direct file reading
// NuGet: dotnet add package IronBarcode
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
var results = BarcodeReader.Read("barcode.png");
foreach (var result in results)
    Console.WriteLine($"{result.Value} ({result.Format})");
Imports IronBarCode

' IronBarcode: direct file reading
' NuGet: dotnet add package IronBarcode
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim results = BarcodeReader.Read("barcode.png")
For Each result In results
    Console.WriteLine($"{result.Value} ({result.Format})")
Next
$vbLabelText   $csharpLabel

整個相機管道塊——上下文建立、設置、條碼型別啟用、相機獲取、幀源分配、狀態轉換——被授權密鑰分配和一次方法調用所取代。

IronBarcode對比Scandit SDK:功能比較

功能 Scandit SDK IronBarcode
主要部署 移動相機掃描 伺服器、雲端、桌面文件處理
需要相機
圖像文件讀取 未設計為 主要輸入型別
PDF條碼提取 不支持 本地多頁支持
流/字節陣列輸入 不支持
自動格式檢測 否(必須指定) 是(預設行為)
事件驅動結果 是(條碼掃描回調) 否(同步返回)
ASP.NET Core/伺服器端 未設計為 完全支持
Azure Functions/無伺服器 不實用 完全支持
Docker / Linux 不支持 完全支持
條碼生成 不支持 包含在包中
多條碼檢測 MatrixScan(單獨產品) 包含在包中
定價模式 聯繫銷售(每個產品) 公佈的永久層級
每次掃描/每個裝置費用

快速開始

步驟 1:替換 NuGet 包

移除Scandit套件:

dotnet remove package Scandit.BarcodePicker
dotnet remove package Scandit.DataCapture.Core
dotnet remove package Scandit.DataCapture.Barcode
dotnet remove package Scandit.BarcodePicker
dotnet remove package Scandit.DataCapture.Core
dotnet remove package Scandit.DataCapture.Barcode
SHELL

安裝IronBarcode:

dotnet add package IronBarcode
dotnet add package IronBarcode
SHELL

步驟 2:更新命名空間

將Scandit命名空間導入替換為IronBarcode命名空間:

// Before (Scandit SDK)
using Scandit.DataCapture.Core;
using Scandit.DataCapture.Barcode;
using Scandit.DataCapture.Barcode.Data;

// After (IronBarcode)
using IronBarCode;
// Before (Scandit SDK)
using Scandit.DataCapture.Core;
using Scandit.DataCapture.Barcode;
using Scandit.DataCapture.Barcode.Data;

// After (IronBarcode)
using IronBarCode;
' Before (Scandit SDK)
Imports Scandit.DataCapture.Core
Imports Scandit.DataCapture.Barcode
Imports Scandit.DataCapture.Barcode.Data

' After (IronBarcode)
Imports IronBarCode
$vbLabelText   $csharpLabel

步驟 3:初始化授權

在應用程式啟動時新增授權初始化,替換DataCaptureContext.ForLicenseKey呼叫:

// Before (Scandit SDK)
var dataCaptureContext = DataCaptureContext.ForLicenseKey("YOUR-SCANDIT-LICENSE");

// After (IronBarcode)
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// Before (Scandit SDK)
var dataCaptureContext = DataCaptureContext.ForLicenseKey("YOUR-SCANDIT-LICENSE");

// After (IronBarcode)
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
' Before (Scandit SDK)
Dim dataCaptureContext = DataCaptureContext.ForLicenseKey("YOUR-SCANDIT-LICENSE")

' After (IronBarcode)
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

程式碼遷移範例

從圖片文件讀取條碼

處理靜態圖片文件是IronBarcode中支持的核心場景,而Scandit中不支持該工作流。 Scandit SDK處理實時相機幀; 讀取文件需要將捕捉流程適應為將位圖作為幀源,這無原生實現。

Scandit SDK 方法:

// Scandit SDK has no direct file-read API.
// Reading a static image requires constructing a bitmap frame source
// and routing it through the capture pipeline — an unsupported workaround.
// The standard Scandit integration assumes a running camera at all times.
// Scandit SDK has no direct file-read API.
// Reading a static image requires constructing a bitmap frame source
// and routing it through the capture pipeline — an unsupported workaround.
// The standard Scandit integration assumes a running camera at all times.
' Scandit SDK has no direct file-read API.
' Reading a static image requires constructing a bitmap frame source
' and routing it through the capture pipeline — an unsupported workaround.
' The standard Scandit integration assumes a running camera at all times.
$vbLabelText   $csharpLabel

IronBarcode 方法:

// NuGet: dotnet add package IronBarcode
using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var results = BarcodeReader.Read("product-label.png");
foreach (var result in results)
{
    Console.WriteLine($"Value: {result.Value}");
    Console.WriteLine($"Format: {result.Format}");
    Console.WriteLine($"Confidence: {result.Confidence}%");
}
// NuGet: dotnet add package IronBarcode
using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var results = BarcodeReader.Read("product-label.png");
foreach (var result in results)
{
    Console.WriteLine($"Value: {result.Value}");
    Console.WriteLine($"Format: {result.Format}");
    Console.WriteLine($"Confidence: {result.Confidence}%");
}
Imports IronBarCode

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"

Dim results = BarcodeReader.Read("product-label.png")
For Each result In results
    Console.WriteLine($"Value: {result.Value}")
    Console.WriteLine($"Format: {result.Format}")
    Console.WriteLine($"Confidence: {result.Confidence}%")
Next
$vbLabelText   $csharpLabel

從圖片中讀取條碼 使用IronBarcode不需要管道設置。結果集在方法返回後立即可用,無需事件訂閱。

從PDF文件中提取條碼

當從Scandit遷移時,PDF條碼提取是全新的領域,Scandit中不支持PDF。 IronBarcode直接讀取PDF文件,返回按頁碼索引的結果。

Scandit SDK 方法:

// Scandit SDK: no PDF support.
// Implementing PDF barcode extraction with Scandit requires:
// 1. A separate PDF rendering library to convert pages to raster images
// 2. Routing each rendered image through the camera simulation pipeline
// 3. Correlating results back to page numbers manually
// This is not a supported workflow and requires significant custom engineering.
// Scandit SDK: no PDF support.
// Implementing PDF barcode extraction with Scandit requires:
// 1. A separate PDF rendering library to convert pages to raster images
// 2. Routing each rendered image through the camera simulation pipeline
// 3. Correlating results back to page numbers manually
// This is not a supported workflow and requires significant custom engineering.
' Scandit SDK: no PDF support.
' Implementing PDF barcode extraction with Scandit requires:
' 1. A separate PDF rendering library to convert pages to raster images
' 2. Routing each rendered image through the camera simulation pipeline
' 3. Correlating results back to page numbers manually
' This is not a supported workflow and requires significant custom engineering.
$vbLabelText   $csharpLabel

IronBarcode 方法:

// NuGet: dotnet add package IronBarcode
using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var results = BarcodeReader.Read("shipping-manifest.pdf");
foreach (var result in results)
{
    Console.WriteLine($"Page {result.PageNumber}: {result.Value} ({result.Format})");
}
// NuGet: dotnet add package IronBarcode
using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var results = BarcodeReader.Read("shipping-manifest.pdf");
foreach (var result in results)
{
    Console.WriteLine($"Page {result.PageNumber}: {result.Value} ({result.Format})");
}
Imports IronBarCode

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"

Dim results = BarcodeReader.Read("shipping-manifest.pdf")
For Each result In results
    Console.WriteLine($"Page {result.PageNumber}: {result.Value} ({result.Format})")
Next
$vbLabelText   $csharpLabel

對於從PDF文件中讀取條碼的完整指導,包括頁面範圍選擇和多條碼處理,IronBarcode文件涵蓋了完整的PDF處理場景。 不需要額外的PDF程式庫依賴。

將事件回調轉換為直接返回值

Scandit通過BarcodeScanned事件提供條碼結果,因為即時相機掃描本質上是非同步的——當相機在當前幀中檢測到條碼時,結果才會到達。 IronBarcode返回結果作為型別化的集合,因為基於文件的讀取有一個已知的完成邊界。 這是遷移中結構上最有意義的變化之一。

Scandit SDK 方法:

// Scandit SDK: event-driven result delivery
barcodeCapture.BarcodeScanned += (sender, args) =>
{
    foreach (var barcode in args.Session.NewlyRecognizedBarcodes)
    {
        string value = barcode.Data;
        string symbology = barcode.Symbology.ToString();

        // Processing logic embedded inside event handler
        LogBarcodeResult(value, symbology);
        UpdateInventory(value);
    }
};

// Scan continues indefinitely until camera session is terminated
// Scandit SDK: event-driven result delivery
barcodeCapture.BarcodeScanned += (sender, args) =>
{
    foreach (var barcode in args.Session.NewlyRecognizedBarcodes)
    {
        string value = barcode.Data;
        string symbology = barcode.Symbology.ToString();

        // Processing logic embedded inside event handler
        LogBarcodeResult(value, symbology);
        UpdateInventory(value);
    }
};

// Scan continues indefinitely until camera session is terminated
Imports System

' Scandit SDK: event-driven result delivery
AddHandler barcodeCapture.BarcodeScanned, Sub(sender, args)
    For Each barcode In args.Session.NewlyRecognizedBarcodes
        Dim value As String = barcode.Data
        Dim symbology As String = barcode.Symbology.ToString()

        ' Processing logic embedded inside event handler
        LogBarcodeResult(value, symbology)
        UpdateInventory(value)
    Next
End Sub

' Scan continues indefinitely until camera session is terminated
$vbLabelText   $csharpLabel

IronBarcode 方法:

// NuGet: dotnet add package IronBarcode
using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var results = BarcodeReader.Read("document.png");
foreach (var result in results)
{
    // Same processing logic, now in standard control flow
    LogBarcodeResult(result.Value, result.Format.ToString());
    UpdateInventory(result.Value);
}
// NuGet: dotnet add package IronBarcode
using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var results = BarcodeReader.Read("document.png");
foreach (var result in results)
{
    // Same processing logic, now in standard control flow
    LogBarcodeResult(result.Value, result.Format.ToString());
    UpdateInventory(result.Value);
}
Imports IronBarCode

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"

Dim results = BarcodeReader.Read("document.png")
For Each result In results
    ' Same processing logic, now in standard control flow
    LogBarcodeResult(result.Value, result.Format.ToString())
    UpdateInventory(result.Value)
Next
$vbLabelText   $csharpLabel

所有內嵌在事件處理程式回調中的處理邏輯都移入標準的順序程式碼中。 錯誤處理、記錄和下游操作可使用普通的控制流程結構,而不是事件處理程式模式。

ASP.NET Core文件上傳端點

一個無狀態的伺服器端點從上傳的文件中讀取條碼,代表IronBarcode的主要伺服器端用例。 這一模式不支持Scandit的相機管道架構。

Scandit SDK 方法:

// Scandit SDK: not applicable to ASP.NET Core file upload scenarios.
// The DataCaptureContext requires a camera hardware session.
// There is no mechanism to process an IFormFile through the Scandit pipeline
// without substantial custom camera-simulation infrastructure.
// Scandit SDK: not applicable to ASP.NET Core file upload scenarios.
// The DataCaptureContext requires a camera hardware session.
// There is no mechanism to process an IFormFile through the Scandit pipeline
// without substantial custom camera-simulation infrastructure.
' Scandit SDK: not applicable to ASP.NET Core file upload scenarios.
' The DataCaptureContext requires a camera hardware session.
' There is no mechanism to process an IFormFile through the Scandit pipeline
' without substantial custom camera-simulation infrastructure.
$vbLabelText   $csharpLabel

IronBarcode 方法:

// NuGet: dotnet add package IronBarcode
using IronBarCode;

[ApiController]
[Route("api/[controller]")]
public class BarcodeController : ControllerBase
{
    [HttpPost("scan")]
    public IActionResult ScanUploadedDocument(IFormFile file)
    {
        if (file == null || file.Length == 0)
            return BadRequest("No file provided");

        using var stream = file.OpenReadStream();
        var results = BarcodeReader.Read(stream);

        if (!results.Any())
            return NotFound("No barcodes detected");

        return Ok(results.Select(r => new
        {
            r.Value,
            Format = r.Format.ToString(),
            r.PageNumber
        }));
    }
}
// NuGet: dotnet add package IronBarcode
using IronBarCode;

[ApiController]
[Route("api/[controller]")]
public class BarcodeController : ControllerBase
{
    [HttpPost("scan")]
    public IActionResult ScanUploadedDocument(IFormFile file)
    {
        if (file == null || file.Length == 0)
            return BadRequest("No file provided");

        using var stream = file.OpenReadStream();
        var results = BarcodeReader.Read(stream);

        if (!results.Any())
            return NotFound("No barcodes detected");

        return Ok(results.Select(r => new
        {
            r.Value,
            Format = r.Format.ToString(),
            r.PageNumber
        }));
    }
}
Imports IronBarCode
Imports Microsoft.AspNetCore.Mvc

<ApiController>
<Route("api/[controller]")>
Public Class BarcodeController
    Inherits ControllerBase

    <HttpPost("scan")>
    Public Function ScanUploadedDocument(file As IFormFile) As IActionResult
        If file Is Nothing OrElse file.Length = 0 Then
            Return BadRequest("No file provided")
        End If

        Using stream = file.OpenReadStream()
            Dim results = BarcodeReader.Read(stream)

            If Not results.Any() Then
                Return NotFound("No barcodes detected")
            End If

            Return Ok(results.Select(Function(r) New With {
                .Value = r.Value,
                .Format = r.Format.ToString(),
                .PageNumber = r.PageNumber
            }))
        End Using
    End Function
End Class
$vbLabelText   $csharpLabel

IFormFile.OpenReadStream(),不需要臨時文件建立。 結果在請求-響應迴圈中同步返回,無需非同步相機管理。

跨多文件的並發批處理

高容量文件隊列需要在多執行緒間進行並行處理。 由於IronBarcode的API是無狀態的,它本質上是執行緒安全的,並可以直接組合與Parallel.ForEach和非同步任務模式。

Scandit SDK 方法:

// Scandit SDK: no supported batch file processing pattern.
// The FrameSourceState model assumes a continuous camera session,
// not a queue of discrete documents. Batch processing would require
// one camera simulation pipeline per document or serialized processing
// through a shared pipeline — neither is a supported workflow.
// Scandit SDK: no supported batch file processing pattern.
// The FrameSourceState model assumes a continuous camera session,
// not a queue of discrete documents. Batch processing would require
// one camera simulation pipeline per document or serialized processing
// through a shared pipeline — neither is a supported workflow.
' Scandit SDK: no supported batch file processing pattern.
' The FrameSourceState model assumes a continuous camera session,
' not a queue of discrete documents. Batch processing would require
' one camera simulation pipeline per document or serialized processing
' through a shared pipeline — neither is a supported workflow.
$vbLabelText   $csharpLabel

IronBarcode 方法:

// NuGet: dotnet add package IronBarcode
using IronBarCode;
using System.Collections.Concurrent;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true,
    MaxParallelThreads = 4
};

var files = Directory.GetFiles("./documents/", "*.pdf");
var allResults = new ConcurrentBag<(string File, BarcodeResult Result)>();

Parallel.ForEach(files, file =>
{
    var results = BarcodeReader.Read(file, options);
    foreach (var result in results)
        allResults.Add((file, result));
});

foreach (var (file, result) in allResults)
    Console.WriteLine($"{Path.GetFileName(file)}: {result.Value} ({result.Format})");
// NuGet: dotnet add package IronBarcode
using IronBarCode;
using System.Collections.Concurrent;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true,
    MaxParallelThreads = 4
};

var files = Directory.GetFiles("./documents/", "*.pdf");
var allResults = new ConcurrentBag<(string File, BarcodeResult Result)>();

Parallel.ForEach(files, file =>
{
    var results = BarcodeReader.Read(file, options);
    foreach (var result in results)
        allResults.Add((file, result));
});

foreach (var (file, result) in allResults)
    Console.WriteLine($"{Path.GetFileName(file)}: {result.Value} ({result.Format})");
Imports IronBarCode
Imports System.Collections.Concurrent
Imports System.IO
Imports System.Threading.Tasks

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"

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

Dim files = Directory.GetFiles("./documents/", "*.pdf")
Dim allResults As New ConcurrentBag(Of (File As String, Result As BarcodeResult))()

Parallel.ForEach(files, Sub(file)
    Dim results = BarcodeReader.Read(file, options)
    For Each result In results
        allResults.Add((file, result))
    Next
End Sub)

For Each item In allResults
    Console.WriteLine($"{Path.GetFileName(item.File)}: {item.Result.Value} ({item.Result.Format})")
Next
$vbLabelText   $csharpLabel

對於涵蓋非同步和多執行緒條碼讀取的高級模式,包括吞吐量調整和執行緒數配置,IronBarcode文件提供詳細指導。

Scandit SDK API到IronBarcode的映射參考

Scandit SDK IronBarcode 注意事項
DataCaptureContext.ForLicenseKey("key") IronBarCode.License.LicenseKey = "key" 一次分配; 無上下文物件
BarcodeCaptureSettings.Create() new BarcodeReaderOptions() 可選; 基本讀取不需要
settings.EnableSymbologies(Symbology.Code128, ...) (not needed) IronBarcode自動檢測所有格式
Camera.GetDefaultCamera() (not applicable) 無相機概念
dataCaptureContext.SetFrameSourceAsync(camera) (not applicable) 無幀源
camera.SwitchToDesiredStateAsync(FrameSourceState.On) (not applicable) 無相機狀態機
barcodeCapture.IsEnabled = true BarcodeReader.Read(path) 單次調用啟動讀取
BarcodeScanned +=事件處理程式 標準foreach over return value 不需要事件系統
args.Session.NewlyRecognizedBarcodes BarcodeReader.Read()的返回值 直接集合
barcode.Data result.Value 相同的語義內容
barcode.Symbology result.Format 等效格式枚舉
using Scandit.DataCapture.Core using IronBarCode 單一命名空間
using Scandit.DataCapture.Barcode using IronBarCode 包含在同一命名空間中
SparkScan產品 BarcodeReader.Read(path) 無需單獨產品
MatrixScan產品 BarcodeReaderOptions { ExpectMultipleBarcodes = true } 包含在基本包中

常見遷移問題及解決方案

問題1:相機管道程式碼沒有直接翻譯

Scandit SDK:DataCaptureContext, BarcodeCaptureSettings, BarcodeCapture設置塊跨7-10行的初始化程式碼,帶有非同步狀態轉換。

解決方案:完全刪除此塊。 它在IronBarcode中沒有對應,因為IronBarcode的基於文件的API不需要會話初始化。 用以下內容替換整個塊:

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
Imports IronBarCode

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

問題2:BarcodeScanned事件處理程式邏輯

Scandit SDK:處理邏輯嵌入在BarcodeScanned +=事件處理程式lambda或方法中。 這一模式在IronBarcode中不存在。

解決方案:將處理程式主體移入標準程式碼,在BarcodeReader.Read調用之後:

// Before: event handler
barcodeCapture.BarcodeScanned += (s, args) =>
{
    foreach (var b in args.Session.NewlyRecognizedBarcodes)
        Console.WriteLine(b.Data);
};

// After: direct iteration
foreach (var result in BarcodeReader.Read("document.png"))
    Console.WriteLine(result.Value);
// Before: event handler
barcodeCapture.BarcodeScanned += (s, args) =>
{
    foreach (var b in args.Session.NewlyRecognizedBarcodes)
        Console.WriteLine(b.Data);
};

// After: direct iteration
foreach (var result in BarcodeReader.Read("document.png"))
    Console.WriteLine(result.Value);
Imports System

' Before: event handler
AddHandler barcodeCapture.BarcodeScanned, Sub(s, args)
    For Each b In args.Session.NewlyRecognizedBarcodes
        Console.WriteLine(b.Data)
    Next
End Sub

' After: direct iteration
For Each result In BarcodeReader.Read("document.png")
    Console.WriteLine(result.Value)
Next
$vbLabelText   $csharpLabel

問題3:EnableSymbologies在程式碼庫中分散的調用

Scandit SDK:程式碼庫中的多個地方可能會因不同的掃描上下文而調用settings.EnableSymbologies(...)異同的條碼型別集合。

解決方案:移除所有EnableSymbologies調用。 IronBarcode預設下自動檢測所有支持的格式。 如果為特定場景中的性能需要限制格式,使用BarcodeReaderOptions.ExpectBarcodeTypes

var options = new BarcodeReaderOptions
{
    ExpectBarcodeTypes = BarcodeEncoding.Code128 | BarcodeEncoding.QRCode
};
var results = BarcodeReader.Read("document.png", options);
var options = new BarcodeReaderOptions
{
    ExpectBarcodeTypes = BarcodeEncoding.Code128 | BarcodeEncoding.QRCode
};
var results = BarcodeReader.Read("document.png", options);
Imports System

Dim options As New BarcodeReaderOptions With {
    .ExpectBarcodeTypes = BarcodeEncoding.Code128 Or BarcodeEncoding.QRCode
}
Dim results = BarcodeReader.Read("document.png", options)
$vbLabelText   $csharpLabel

問題4:現有程式碼庫中無PDF讀取

Scandit SDK:如果現有程式碼庫在將PDF頁面轉換為圖像輸入到Scandit管道之前進行,則此自定義渲染基礎結構不再需要。

解決方案:完全移除PDF轉圖像的渲染步驟。 將PDF路徑直接傳遞給IronBarcode:

// Before: render PDF pages to images, then pass each image to Scandit pipeline
// (multiple steps, external PDF library dependency)

// After: pass PDF directly to IronBarcode
var results = BarcodeReader.Read("document.pdf");
// Results include PageNumber property for each detected barcode
// Before: render PDF pages to images, then pass each image to Scandit pipeline
// (multiple steps, external PDF library dependency)

// After: pass PDF directly to IronBarcode
var results = BarcodeReader.Read("document.pdf");
// Results include PageNumber property for each detected barcode
' Before: render PDF pages to images, then pass each image to Scandit pipeline
' (multiple steps, external PDF library dependency)

' After: pass PDF directly to IronBarcode
Dim results = BarcodeReader.Read("document.pdf")
' Results include PageNumber property for each detected barcode
$vbLabelText   $csharpLabel

問題5:非同步相機初始化模式

Scandit SDK:相機初始化使用SwitchToDesiredStateAsync。 如果調用程式碼依賴於這些非同步操作的結構,刪除它們簡化了非同步鏈。

解決方案:完全移除非同步相機初始化。 BarcodeReader.Read是同步的。 如果在UI或伺服器上下文中需要非同步執行以提高響應性,將其包裹在Task.Run

// Async wrapper for non-blocking execution
var results = await Task.Run(() => BarcodeReader.Read("document.png"));
// Async wrapper for non-blocking execution
var results = await Task.Run(() => BarcodeReader.Read("document.png"));
Imports System.Threading.Tasks

' Async wrapper for non-blocking execution
Dim results = Await Task.Run(Function() BarcodeReader.Read("document.png"))
$vbLabelText   $csharpLabel

Scandit SDK遷移清單

遷移前任務

審核程式碼庫中所有Scandit整合點:

grep -r "DataCaptureContext\|BarcodeCaptureSettings\|BarcodeCapture" --include="*.cs" .
grep -r "EnableSymbologies\|BarcodeScanned\|NewlyRecognizedBarcodes" --include="*.cs" .
grep -r "using Scandit" --include="*.cs" .
grep -r "barcode\.Data\|barcode\.Symbology\|FrameSourceState" --include="*.cs" .
grep -r "DataCaptureContext\|BarcodeCaptureSettings\|BarcodeCapture" --include="*.cs" .
grep -r "EnableSymbologies\|BarcodeScanned\|NewlyRecognizedBarcodes" --include="*.cs" .
grep -r "using Scandit" --include="*.cs" .
grep -r "barcode\.Data\|barcode\.Symbology\|FrameSourceState" --include="*.cs" .
SHELL

記錄所有掃描上下文——確定哪些程式碼路徑處理即時相機掃描(仍使用Scandit),哪些處理文件或文件處理(遷移到IronBarcode)。 注意在Scandit處理之前渲染的所有PDF頁面的地方,因為該渲染步驟將被淘汰。

程式碼更新任務

  1. 移除Scandit NuGet套件(Scandit.BarcodePicker, Scandit.DataCapture.Core, Scandit.DataCapture.Barcode
  2. 安裝IronBarcode NuGet套件
  3. using Scandit.DataCapture.*導入
  4. 完全刪除DataCaptureContext初始化塊
  5. 刪除所有SetFrameSourceAsync調用
  6. 刪除所有EnableSymbologies調用
  7. barcodeCapture.IsEnabled = true
  8. foreach over BarcodeReader.Read()結果
  9. barcode.Data
  10. barcode.Symbology
  11. 移除PDF轉圖像渲染管道現在IronBarcode直接讀取PDF
  12. 在應用程式啟動時新增IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"

遷移後測試

在完成程式碼更新後驗證以下內容:

  • 確認IronBarcode返回的條碼值匹配同一輸入文件之前由Scandit返回的值
  • 驗證文件集中所有支持的條碼格式無需ExpectBarcodeTypes配置即可被檢測到
  • 測試PDF提取返回正確的PageNumber值多頁文件
  • 在預期負載下確認ASP.NET Core端點在可接受的響應時間內返回結果
  • 驗證Docker或容器化部署在無相機硬體的情況下成功完成條碼讀取
  • 測試並發批處理使用Parallel.ForEach在無競賽條件下生成正確的結果
  • 確認應用程式在IronBarcode授權密鑰替代Scandit上下文的情況下正確啟動和初始化

遷移到IronBarcode的主要優勢

消除相機管道開銷:移除DataCaptureContext初始化序列消除了狀態相機管理、非同步狀態轉換和平台特定相機API從伺服器端程式碼中。 結果程式碼更簡單、更短,沒有帶有平台限制,這些限制無法在Linux上部署,在Docker容器中,或在無伺服器計算環境中。

直接PDF處理:原生PDF條碼提取消除了對單獨PDF渲染程式庫的依賴,頁面到圖像之間的工程開銷,和該依賴的額外授權成本。 多頁PDF文件通過單次方法調用處理,頁面索引結果立即可用。

同步無狀態API:直接返回值模式替換事件驅動的回調模式為標準順序程式碼。 錯誤處理、記錄和下游處理自然與現有應用程式架構整合,不需要事件訂閱管理或非同步狀態機協調。

公開透明的定價:公佈的永久授權層次為749美元、1499美元和2999美元,允許預算提案、供應商比較和採購流程不需經過銷售迴圈。 在編寫整合程式碼之前即可確定授權成本。

全雲端和容器支持:IronBarcode的無狀態、硬體獨立API在Azure Functions,AWS Lambda,Docker容器上的Linux以及任何其他具有.NET運行時的計算環境中無需修改即可運行。 不需要相機模擬,無硬體依賴性解決方法和無平台特定配置即可在這些環境中部署。

自動格式檢測:移除EnableSymbologies聲明意味著攜帶意外條碼格式的輸入文件可以正確處理,無需程式碼更改。 當輸入文件中包含的格式集發生更改時——新的供應商,新的標籤格式,新的文件型別——IronBarcode會自動處理新格式。

請注意Scandit是其各自擁有者的註冊商標。 本網站與Scandit無關,未獲Scandit認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供資訊參考,並反映了撰寫時公開可用的資訊。

常見問題

我為什麼應該從Scandit SDK遷移到IronBarcode?

常見的理由包括簡化授權(去除SDK +運行時鑰匙的複雜性)、消除吞吐量限制、獲得原生PDF支持、改善Docker/CI/CD部署,並減少生產程式碼中的API樣板。

如何用IronBarcode替換Scandit API呼叫?

用IronBarCode.License.LicenseKey = "key"替換實例建立和授權樣板。用BarcodeReader.Read(path)替換讀取呼叫,用BarcodeWriter.CreateBarcode(data, encoding)替換寫入呼叫。靜態方法不需要實例管理。

從Scandit SDK遷移到IronBarcode需要多少程式碼變更?

大多數遷移會導致較少的程式碼行。授權樣板、實例構造函式和顯式格式配置被移除。核心讀/寫操作映射為較短的IronBarcode等價物,且結果物件更清晰。

我需要在遷移期間同時安裝Scandit SDK和IronBarcode嗎?

不需要。大多數遷移是直接替換而不是並行操作。一次遷移一個服務類,替換NuGet引用,並更新實例化和API呼叫模式後再移動到下一個類。

IronBarcode的NuGet包名稱是什麼?

包名是'IronBarCode'(大寫B和C)。可以用'Install-Package IronBarCode'或'dotnet add package IronBarCode'安裝。程式碼中的using指令是'using IronBarCode;'。

IronBarcode如何簡化與Scandit SDK相比的Docker部署?

IronBarcode是沒有外部SDK文件或掛載許可配置的NuGet封裝。在Docker中,設置IRONBARCODE_LICENSE_KEY環境變數,包在啟動時處理許可驗證。

從Scandit遷移後,IronBarcode是否自動檢測所有條碼格式?

是的。IronBarcode自動檢測所有支持的格式的符號學。不需要顯式的BarcodeTypes枚舉。如果格式已經知道並且性能很重要,BarcodeReaderOptions允許限制搜索空間作為優化。

IronBarcode是否可以不使用單獨的庫讀取PDF中的條碼?

可以。BarcodeReader.Read("document.pdf")原生處理PDF文件。結果包括每個條碼發現的頁碼、格式、值和置信度。不需要外部PDF渲染步驟。

IronBarcode如何處理並行條碼處理?

IronBarcode的靜態方法是無狀態且執行緒安全的。直接使用Parallel.ForEach遍歷文件列表,不需要每個執行緒的實例管理。BarcodeReaderOptions.MaxParallelThreads控制內部執行緒預算。

從Scandit SDK遷移到IronBarcode時,有哪些結果屬性會改變?

常見的重命名:BarcodeValue變為Value,BarcodeType變為Format。IronBarcode結果還新增了Confidence和PageNumber。整個解決方案的搜索和替換可處理現有結果處理程式碼中的重新命名。

我如何在CI/CD管道中設置IronBarcode授權?

將IRONBARCODE_LICENSE_KEY作為管道機密儲存,在應用程式啟動程式碼中分配IronBarCode.License.LicenseKey。一個機密涵蓋所有環境,包括開發、測試、分期和生產。

IronBarcode是否支持生成帶有自定義樣式的QR碼?

支持。QRCodeWriter.CreateQrCode()支持通過ChangeBarCodeColor()自定義顏色,通過AddBrandLogo()嵌入logo,可配置錯誤校正級別,以及包括PNG、JPG、PDF和流在內的多種輸出格式。

Curtis Chau
技術作家

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

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

Iron 支援團隊

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