Altbilgi içeriğine atla
VIDEOLAR

IronBarcode kullanarak .NET için C#'ta Barkod Görüntüleri Nasıl Oluşturulur

Dynamsoft Barkod Okuyucu'dan IronBarcode'a Geçiş

Dynamsoft Barkod Okuyucu'dan IronBarcode'a göç eden çoğu geliştirici iki gruptan birine düşer: İyi duyulmuş bir itici olan Dynamsoft'u seçenler ve daha sonra kamera merkezli API'nin bir belge işleme kullanım senaryosuna uygun olmadığını keşfedenler ve lisans sunucusu bağımlılığının üretim olaylarına neden olduğu hava boşluklu veya Docker ortamlarında çalışanlar.

İlk gruptaysanız, geçiş, harici PDF görüntüleme kütüphanesini, sayfa başına render döngüsünü ve hata kodu lisans modelini kaldırır. Eğer ikinci grupta yer alıyorsanız, geçiş işlemi InitLicense ağ çağrısını, çevrimdışı lisans-içerik paketini ve yenileme döngüsünü ve dışa giden ağ politikasını Docker veya VPC yapılandırmanızdan kaldırır. Her iki durumda da, kod tabanı bu geçişten sonra daha kısa olur.

Bu kılavuz, kaybettiklerinizle ilgili dürüsttür: eğer uygulamanız gerçek zamanlı kamera karelerini işliyorsa, Dynamsoft'un Capture Vision iş hattı bu iş yükü için ayarlanmıştır ve IronBarcode doğru bir yedek değildir. Bu geçiş kılavuzu, sunucu tarafı dosya işleme, belge iş akışları ve lisans sunucusu erişiminin bir sorun olduğu ortamlara yöneliktir.

Adım 1: NuGet Paketlerini Değiştirin

dotnet remove package Dynamsoft.DotNet.BarcodeReader.Bundle
dotnet add package BarCode
dotnet remove package Dynamsoft.DotNet.BarcodeReader.Bundle
dotnet add package BarCode
SHELL

Projenize yalnızca Dynamsoft için eklenmiş bir PDF görüntüleme kütüphanesi varsa (PdfiumViewer en yaygın olanıdır), o da kaldırılabilir:

# Remove if added only for Dynamsoft PDF support
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Native.x86_64.v8-xfa
# Remove if added only for Dynamsoft PDF support
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Native.x86_64.v8-xfa
SHELL

Adım 2: Lisans Başlatmayı Değiştirin

İlk basitleşmenin gerçekleştiği yer burasıdır. Dynamsoft modeli, her başlangıçta bir hata kodu kontrolü ve istisna yönetimi gerektirir:

Önce — Dynamsoft:

using Dynamsoft.License;
using Dynamsoft.Core;

// Must run before any barcode operations
int errorCode = LicenseManager.InitLicense("YOUR-DYNAMSOFT-KEY", out string errorMsg);
if (errorCode != (int)EnumErrorCode.EC_OK)
    throw new InvalidOperationException($"License validation failed [{errorCode}]: {errorMsg}");
using Dynamsoft.License;
using Dynamsoft.Core;

// Must run before any barcode operations
int errorCode = LicenseManager.InitLicense("YOUR-DYNAMSOFT-KEY", out string errorMsg);
if (errorCode != (int)EnumErrorCode.EC_OK)
    throw new InvalidOperationException($"License validation failed [{errorCode}]: {errorMsg}");
Imports Dynamsoft.License
Imports Dynamsoft.Core

' Must run before any barcode operations
Dim errorCode As Integer = LicenseManager.InitLicense("YOUR-DYNAMSOFT-KEY", errorMsg)
If errorCode <> CType(EnumErrorCode.EC_OK, Integer) Then
    Throw New InvalidOperationException($"License validation failed [{errorCode}]: {errorMsg}")
End If
$vbLabelText   $csharpLabel

Sonrası — IronBarcode:

// NuGet: dotnet add package BarCode
using IronBarCode;

// Local validation — no network call, no error code
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// NuGet: dotnet add package BarCode
using IronBarCode;

// Local validation — no network call, no error code
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
Imports IronBarCode

' Local validation — no network call, no error code
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

Bir ASP.NET Core uygulamasında, bunu Program.cs öncesinde builder.Build() içerisine ekleyin:

IronBarCode.License.LicenseKey = Environment.GetEnvironmentVariable("IRONBARCODE_KEY")
    ?? "YOUR-LICENSE-KEY";
IronBarCode.License.LicenseKey = Environment.GetEnvironmentVariable("IRONBARCODE_KEY")
    ?? "YOUR-LICENSE-KEY";
Imports IronBarCode

IronBarCode.License.LicenseKey = If(Environment.GetEnvironmentVariable("IRONBARCODE_KEY"), "YOUR-LICENSE-KEY")
$vbLabelText   $csharpLabel

Bir Docker veya Kubernetes ortamında, dağıtım manifestosunda IRONBARCODE_KEY ortam değişkenini ayarlayın. Dışa giden ağ kuralları gerekli değildir.

Adım 3: Ad Alanı İthalatlarını Değiştirin

Tüm kaynak dosyaları genelinde bul ve değiştir:

grep -r "using Dynamsoft\." --include="*.cs" .
grep -r "using Dynamsoft\." --include="*.cs" .
SHELL

Her oluşumu değiştirin:

// Before
using Dynamsoft.CVR;
using Dynamsoft.DBR;
using Dynamsoft.License;
using Dynamsoft.Core;

// After
using IronBarCode;
// Before
using Dynamsoft.CVR;
using Dynamsoft.DBR;
using Dynamsoft.License;
using Dynamsoft.Core;

// After
using IronBarCode;
Imports IronBarCode
$vbLabelText   $csharpLabel

Kod Göç Örnekleri

Temel Dosya Okuma

En temel işlem — bir resim dosyasından barkod okuma.

Önce — Dynamsoft:

using Dynamsoft.CVR;
using Dynamsoft.DBR;

public string ReadBarcodeFromFile(CaptureVisionRouter router, string imagePath)
{
    CapturedResult result = router.Capture(imagePath, PresetTemplate.PT_READ_BARCODES);
    BarcodeResultItem[] items = result.GetDecodedBarcodesResult()?.GetItems();
    if (items == null || items.Length == 0)
        return null;

    return items[0].GetText();
}
using Dynamsoft.CVR;
using Dynamsoft.DBR;

public string ReadBarcodeFromFile(CaptureVisionRouter router, string imagePath)
{
    CapturedResult result = router.Capture(imagePath, PresetTemplate.PT_READ_BARCODES);
    BarcodeResultItem[] items = result.GetDecodedBarcodesResult()?.GetItems();
    if (items == null || items.Length == 0)
        return null;

    return items[0].GetText();
}
Imports Dynamsoft.CVR
Imports Dynamsoft.DBR

Public Function ReadBarcodeFromFile(router As CaptureVisionRouter, imagePath As String) As String
    Dim result As CapturedResult = router.Capture(imagePath, PresetTemplate.PT_READ_BARCODES)
    Dim items As BarcodeResultItem() = result.GetDecodedBarcodesResult()?.GetItems()
    If items Is Nothing OrElse items.Length = 0 Then
        Return Nothing
    End If

    Return items(0).GetText()
End Function
$vbLabelText   $csharpLabel

Sonrası — IronBarcode:

// NuGet: dotnet add package BarCode
using IronBarCode;

public string ReadBarcodeFromFile(string imagePath)
{
    var results = BarcodeReader.Read(imagePath);
    return results?.FirstOrDefault()?.Value;
}
// NuGet: dotnet add package BarCode
using IronBarCode;

public string ReadBarcodeFromFile(string imagePath)
{
    var results = BarcodeReader.Read(imagePath);
    return results?.FirstOrDefault()?.Value;
}
Imports IronBarCode

Public Function ReadBarcodeFromFile(imagePath As String) As String
    Dim results = BarcodeReader.Read(imagePath)
    Return results?.FirstOrDefault()?.Value
End Function
$vbLabelText   $csharpLabel

Yönlendirici örneği yok oldu. BarcodeReader.Read statiktir. BarcodeResultItem.GetText(), .Value olur. LINQ ile results üzerindeki null kontrolü daha temizdir.

Birden Fazla Barkod Okuma

Önce — Dynamsoft:

using Dynamsoft.CVR;
using Dynamsoft.DBR;

public List<string> ReadAllBarcodes(CaptureVisionRouter router, string imagePath)
{
    SimplifiedCaptureVisionSettings settings = router.GetSimplifiedSettings(
        PresetTemplate.PT_READ_BARCODES);
    settings.BarcodeSettings.ExpectedBarcodesCount = 0; // 0 = find all
    router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings);

    CapturedResult result = router.Capture(imagePath, PresetTemplate.PT_READ_BARCODES);
    BarcodeResultItem[] items = result.GetDecodedBarcodesResult()?.GetItems();
    var values = new List<string>();

    if (items != null)
    {
        foreach (var item in items)
            values.Add(item.GetText());
    }

    return values;
}
using Dynamsoft.CVR;
using Dynamsoft.DBR;

public List<string> ReadAllBarcodes(CaptureVisionRouter router, string imagePath)
{
    SimplifiedCaptureVisionSettings settings = router.GetSimplifiedSettings(
        PresetTemplate.PT_READ_BARCODES);
    settings.BarcodeSettings.ExpectedBarcodesCount = 0; // 0 = find all
    router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings);

    CapturedResult result = router.Capture(imagePath, PresetTemplate.PT_READ_BARCODES);
    BarcodeResultItem[] items = result.GetDecodedBarcodesResult()?.GetItems();
    var values = new List<string>();

    if (items != null)
    {
        foreach (var item in items)
            values.Add(item.GetText());
    }

    return values;
}
Imports Dynamsoft.CVR
Imports Dynamsoft.DBR

Public Function ReadAllBarcodes(router As CaptureVisionRouter, imagePath As String) As List(Of String)
    Dim settings As SimplifiedCaptureVisionSettings = router.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES)
    settings.BarcodeSettings.ExpectedBarcodesCount = 0 ' 0 = find all
    router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings)

    Dim result As CapturedResult = router.Capture(imagePath, PresetTemplate.PT_READ_BARCODES)
    Dim items As BarcodeResultItem() = result.GetDecodedBarcodesResult()?.GetItems()
    Dim values As New List(Of String)()

    If items IsNot Nothing Then
        For Each item In items
            values.Add(item.GetText())
        Next
    End If

    Return values
End Function
$vbLabelText   $csharpLabel

Sonrası — IronBarcode:

using IronBarCode;

public List<string> ReadAllBarcodes(string imagePath)
{
    var options = new BarcodeReaderOptions
    {
        ExpectMultipleBarcodes = true,
        MaxParallelThreads = 4
    };

    return BarcodeReader.Read(imagePath, options)
        .Select(r => r.Value)
        .ToList();
}
using IronBarCode;

public List<string> ReadAllBarcodes(string imagePath)
{
    var options = new BarcodeReaderOptions
    {
        ExpectMultipleBarcodes = true,
        MaxParallelThreads = 4
    };

    return BarcodeReader.Read(imagePath, options)
        .Select(r => r.Value)
        .ToList();
}
Imports IronBarCode

Public Function ReadAllBarcodes(imagePath As String) As List(Of String)
    Dim options As New BarcodeReaderOptions With {
        .ExpectMultipleBarcodes = True,
        .MaxParallelThreads = 4
    }

    Return BarcodeReader.Read(imagePath, options) _
        .Select(Function(r) r.Value) _
        .ToList()
End Function
$vbLabelText   $csharpLabel

Baytlardan Okuma (Bellek İçi Görüntüler)

Önce — Dynamsoft:

using Dynamsoft.CVR;
using Dynamsoft.Core;
using Dynamsoft.DBR;

// Requires width, height, stride, and pixel format — low-level buffer API
public string ReadFromBuffer(CaptureVisionRouter router, byte[] rawPixels, int width, int height)
{
    var imageData = new ImageData
    {
        Bytes = rawPixels,
        Width = width,
        Height = height,
        Stride = width * 3, // assuming 24bpp RGB
        Format = EnumImagePixelFormat.IPF_RGB_888
    };

    CapturedResult result = router.Capture(imageData, PresetTemplate.PT_READ_BARCODES);
    return result.GetDecodedBarcodesResult()?.GetItems()?.FirstOrDefault()?.GetText();
}
using Dynamsoft.CVR;
using Dynamsoft.Core;
using Dynamsoft.DBR;

// Requires width, height, stride, and pixel format — low-level buffer API
public string ReadFromBuffer(CaptureVisionRouter router, byte[] rawPixels, int width, int height)
{
    var imageData = new ImageData
    {
        Bytes = rawPixels,
        Width = width,
        Height = height,
        Stride = width * 3, // assuming 24bpp RGB
        Format = EnumImagePixelFormat.IPF_RGB_888
    };

    CapturedResult result = router.Capture(imageData, PresetTemplate.PT_READ_BARCODES);
    return result.GetDecodedBarcodesResult()?.GetItems()?.FirstOrDefault()?.GetText();
}
Imports Dynamsoft.CVR
Imports Dynamsoft.Core
Imports Dynamsoft.DBR

' Requires width, height, stride, and pixel format — low-level buffer API
Public Function ReadFromBuffer(router As CaptureVisionRouter, rawPixels As Byte(), width As Integer, height As Integer) As String
    Dim imageData As New ImageData With {
        .Bytes = rawPixels,
        .Width = width,
        .Height = height,
        .Stride = width * 3, ' assuming 24bpp RGB
        .Format = EnumImagePixelFormat.IPF_RGB_888
    }

    Dim result As CapturedResult = router.Capture(imageData, PresetTemplate.PT_READ_BARCODES)
    Return result.GetDecodedBarcodesResult()?.GetItems()?.FirstOrDefault()?.GetText()
End Function
$vbLabelText   $csharpLabel

Sonrası — IronBarcode:

using IronBarCode;

// Pass PNG/JPEG/BMP bytes directly — no pixel format or stride calculation
public string ReadFromImageBytes(byte[] imageBytes)
{
    return BarcodeReader.Read(imageBytes)?.FirstOrDefault()?.Value;
}
using IronBarCode;

// Pass PNG/JPEG/BMP bytes directly — no pixel format or stride calculation
public string ReadFromImageBytes(byte[] imageBytes)
{
    return BarcodeReader.Read(imageBytes)?.FirstOrDefault()?.Value;
}
Imports IronBarCode

Public Function ReadFromImageBytes(imageBytes As Byte()) As String
    Return BarcodeReader.Read(imageBytes)?.FirstOrDefault()?.Value
End Function
$vbLabelText   $csharpLabel

Uygulamanız daha önce Dynamsoft için resim baytlarını ham piksel tamponuna dönüştürdüyse, kod çözüp ham piksellere dönüştürmeden önce özgün kodlanmış resim baytlarını (PNG, JPEG, BMP) doğrudan IronBarcode'a geçebilirsiniz.

PDF Barkod Okuma — Döngü Renderini Kaldırın

Bu genellikle geçişte en büyük kod azaltımıdır. Tüm PdfiumViewer render döngüsünü kaldırın ve tek bir çağrı ile değiştirin.

Önce — Dynamsoft ve PdfiumViewer ile:

// Requires: Dynamsoft.DotNet.BarcodeReader.Bundle + PdfiumViewer + PdfiumViewer.Native.*
using Dynamsoft.CVR;
using Dynamsoft.DBR;
using PdfiumViewer;
using System.Drawing.Imaging;

public List<string> ReadBarcodesFromPdf(CaptureVisionRouter router, string pdfPath)
{
    var allBarcodes = new List<string>();

    using (var pdfDoc = PdfDocument.Load(pdfPath))
    {
        for (int page = 0; page < pdfDoc.PageCount; page++)
        {
            using var image = pdfDoc.Render(page, 300, 300, true);
            using var ms = new MemoryStream();
            image.Save(ms, ImageFormat.Png);

            CapturedResult result = router.Capture(ms.ToArray(),
                PresetTemplate.PT_READ_BARCODES);
            var items = result.GetDecodedBarcodesResult()?.GetItems();
            if (items != null)
            {
                foreach (var item in items)
                    allBarcodes.Add(item.GetText());
            }
        }
    }

    return allBarcodes;
}
// Requires: Dynamsoft.DotNet.BarcodeReader.Bundle + PdfiumViewer + PdfiumViewer.Native.*
using Dynamsoft.CVR;
using Dynamsoft.DBR;
using PdfiumViewer;
using System.Drawing.Imaging;

public List<string> ReadBarcodesFromPdf(CaptureVisionRouter router, string pdfPath)
{
    var allBarcodes = new List<string>();

    using (var pdfDoc = PdfDocument.Load(pdfPath))
    {
        for (int page = 0; page < pdfDoc.PageCount; page++)
        {
            using var image = pdfDoc.Render(page, 300, 300, true);
            using var ms = new MemoryStream();
            image.Save(ms, ImageFormat.Png);

            CapturedResult result = router.Capture(ms.ToArray(),
                PresetTemplate.PT_READ_BARCODES);
            var items = result.GetDecodedBarcodesResult()?.GetItems();
            if (items != null)
            {
                foreach (var item in items)
                    allBarcodes.Add(item.GetText());
            }
        }
    }

    return allBarcodes;
}
Imports Dynamsoft.CVR
Imports Dynamsoft.DBR
Imports PdfiumViewer
Imports System.Drawing.Imaging

Public Function ReadBarcodesFromPdf(router As CaptureVisionRouter, pdfPath As String) As List(Of String)
    Dim allBarcodes As New List(Of String)()

    Using pdfDoc As PdfDocument = PdfDocument.Load(pdfPath)
        For page As Integer = 0 To pdfDoc.PageCount - 1
            Using image = pdfDoc.Render(page, 300, 300, True)
                Using ms As New MemoryStream()
                    image.Save(ms, ImageFormat.Png)

                    Dim result As CapturedResult = router.Capture(ms.ToArray(), PresetTemplate.PT_READ_BARCODES)
                    Dim items = result.GetDecodedBarcodesResult()?.GetItems()
                    If items IsNot Nothing Then
                        For Each item In items
                            allBarcodes.Add(item.GetText())
                        Next
                    End If
                End Using
            End Using
        Next
    End Using

    Return allBarcodes
End Function
$vbLabelText   $csharpLabel

Sonrası — IronBarcode:

using IronBarCode;

public List<string> ReadBarcodesFromPdf(string pdfPath)
{
    return BarcodeReader.Read(pdfPath)
        .Select(r => r.Value)
        .ToList();
}
using IronBarCode;

public List<string> ReadBarcodesFromPdf(string pdfPath)
{
    return BarcodeReader.Read(pdfPath)
        .Select(r => r.Value)
        .ToList();
}
Imports IronBarCode

Public Function ReadBarcodesFromPdf(pdfPath As String) As List(Of String)
    Return BarcodeReader.Read(pdfPath) _
        .Select(Function(r) r.Value) _
        .ToList()
End Function
$vbLabelText   $csharpLabel

Sayfa döngüsü, PdfDocument, 300 DPI render aşaması, MemoryStream ve her sayfa için Capture çağrısı hepsi kaybolur. IronBarcode PDF sayfalarını dahili olarak işler.

Seçenekli PDF'den okumak mı gerekiyor (yoğun veya zor barkodlar için):

using IronBarCode;

public List<string> ReadBarcodesFromPdfAccurate(string pdfPath)
{
    var options = new BarcodeReaderOptions
    {
        Speed = ReadingSpeed.Balanced,
        ExpectMultipleBarcodes = true
    };

    return BarcodeReader.Read(pdfPath, options)
        .Select(r => r.Value)
        .ToList();
}
using IronBarCode;

public List<string> ReadBarcodesFromPdfAccurate(string pdfPath)
{
    var options = new BarcodeReaderOptions
    {
        Speed = ReadingSpeed.Balanced,
        ExpectMultipleBarcodes = true
    };

    return BarcodeReader.Read(pdfPath, options)
        .Select(r => r.Value)
        .ToList();
}
Imports IronBarCode

Public Function ReadBarcodesFromPdfAccurate(pdfPath As String) As List(Of String)
    Dim options As New BarcodeReaderOptions With {
        .Speed = ReadingSpeed.Balanced,
        .ExpectMultipleBarcodes = True
    }

    Return BarcodeReader.Read(pdfPath, options) _
        .Select(Function(r) r.Value) _
        .ToList()
End Function
$vbLabelText   $csharpLabel

Çevrimdışı / Hava Aralıklı Dağıtım

Mevcut kodunuzda çevrimdışı lisanslama deseni varsa, tamamen kaldırın:

Önce — Dynamsoft çevrimdışı lisansı:

using Dynamsoft.License;
using Dynamsoft.Core;

// Dynamsoft offline: fetch license bundle on a connected machine, persist it,
// then replay it on the offline machine via InitLicenseFromLicenseContent.
int errorCode = LicenseManager.InitLicenseFromLicenseContent(
    licenseContent,
    out string errorMsg);

if (errorCode != (int)EnumErrorCode.EC_OK)
    throw new InvalidOperationException($"Offline license failed: {errorMsg}");
using Dynamsoft.License;
using Dynamsoft.Core;

// Dynamsoft offline: fetch license bundle on a connected machine, persist it,
// then replay it on the offline machine via InitLicenseFromLicenseContent.
int errorCode = LicenseManager.InitLicenseFromLicenseContent(
    licenseContent,
    out string errorMsg);

if (errorCode != (int)EnumErrorCode.EC_OK)
    throw new InvalidOperationException($"Offline license failed: {errorMsg}");
Imports Dynamsoft.License
Imports Dynamsoft.Core

' Dynamsoft offline: fetch license bundle on a connected machine, persist it,
' then replay it on the offline machine via InitLicenseFromLicenseContent.
Dim errorMsg As String
Dim errorCode As Integer = LicenseManager.InitLicenseFromLicenseContent(licenseContent, errorMsg)

If errorCode <> CType(EnumErrorCode.EC_OK, Integer) Then
    Throw New InvalidOperationException($"Offline license failed: {errorMsg}")
End If
$vbLabelText   $csharpLabel

Sonrası — IronBarcode:

// Remove all of the above. Replace with:
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// Remove all of the above. Replace with:
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

Alınacak ve yenilenecek lisans-içerik paketi yok. Bağlı makine önyükleme adımı yok. Anahtar yerel olarak doğrulanır.

Docker Yapılandırması

Eğer daha önce Dynamsoft'un lisans uç noktalarına dışa yönelik HTTPS'e izin vermek için ağ çıkış kuralları veya proxy konfigürasyonu yaptıysanız:

# Before: Docker or Kubernetes egress policy
# Required: Allow outbound HTTPS to Dynamsoft licence endpoints

# After: Remove that egress rule.
# IronBarcode does not require outbound network access for license validation.

# Set license via environment variable
env:
  - name: IRONBARCODE_KEY
    valueFrom:
      secretKeyRef:
        name: ironbarcode-license
        key: key
# Before: Docker or Kubernetes egress policy
# Required: Allow outbound HTTPS to Dynamsoft licence endpoints

# After: Remove that egress rule.
# IronBarcode does not require outbound network access for license validation.

# Set license via environment variable
env:
  - name: IRONBARCODE_KEY
    valueFrom:
      secretKeyRef:
        name: ironbarcode-license
        key: key
YAML

Örnek Yönetimi Temizleme

Dynamsoft, CaptureVisionRouter tabanlı bir örnek API kullanır. Kodunuzda hizmet sınıflarında, alan başlatıcılarında veya DI kayıtlarında yönlendirici örnekleri oluşturuyorsa, tümü kaybolur:

Önce — Dynamsoft örnek yönetimi:

using Dynamsoft.CVR;
using Dynamsoft.DBR;
using Dynamsoft.License;
using Dynamsoft.Core;

public class BarcodeService : IDisposable
{
    private readonly CaptureVisionRouter _router;

    public BarcodeService()
    {
        int errorCode = LicenseManager.InitLicense("KEY", out string errorMsg);
        if (errorCode != (int)EnumErrorCode.EC_OK)
            throw new InvalidOperationException(errorMsg);

        _router = new CaptureVisionRouter();

        var settings = _router.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES);
        settings.BarcodeSettings.ExpectedBarcodesCount = 0;
        _router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings);
    }

    public string[] ReadFile(string path)
    {
        CapturedResult result = _router.Capture(path, PresetTemplate.PT_READ_BARCODES);
        var items = result.GetDecodedBarcodesResult()?.GetItems();
        return items?.Select(i => i.GetText()).ToArray() ?? Array.Empty<string>();
    }

    public void Dispose()
    {
        _router?.Dispose();
    }
}
using Dynamsoft.CVR;
using Dynamsoft.DBR;
using Dynamsoft.License;
using Dynamsoft.Core;

public class BarcodeService : IDisposable
{
    private readonly CaptureVisionRouter _router;

    public BarcodeService()
    {
        int errorCode = LicenseManager.InitLicense("KEY", out string errorMsg);
        if (errorCode != (int)EnumErrorCode.EC_OK)
            throw new InvalidOperationException(errorMsg);

        _router = new CaptureVisionRouter();

        var settings = _router.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES);
        settings.BarcodeSettings.ExpectedBarcodesCount = 0;
        _router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings);
    }

    public string[] ReadFile(string path)
    {
        CapturedResult result = _router.Capture(path, PresetTemplate.PT_READ_BARCODES);
        var items = result.GetDecodedBarcodesResult()?.GetItems();
        return items?.Select(i => i.GetText()).ToArray() ?? Array.Empty<string>();
    }

    public void Dispose()
    {
        _router?.Dispose();
    }
}
Imports Dynamsoft.CVR
Imports Dynamsoft.DBR
Imports Dynamsoft.License
Imports Dynamsoft.Core

Public Class BarcodeService
    Implements IDisposable

    Private ReadOnly _router As CaptureVisionRouter

    Public Sub New()
        Dim errorCode As Integer = LicenseManager.InitLicense("KEY", errorMsg:=Nothing)
        If errorCode <> CType(EnumErrorCode.EC_OK, Integer) Then
            Throw New InvalidOperationException(errorMsg)
        End If

        _router = New CaptureVisionRouter()

        Dim settings = _router.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES)
        settings.BarcodeSettings.ExpectedBarcodesCount = 0
        _router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings)
    End Sub

    Public Function ReadFile(path As String) As String()
        Dim result As CapturedResult = _router.Capture(path, PresetTemplate.PT_READ_BARCODES)
        Dim items = result.GetDecodedBarcodesResult()?.GetItems()
        Return If(items?.Select(Function(i) i.GetText()).ToArray(), Array.Empty(Of String)())
    End Function

    Public Sub Dispose() Implements IDisposable.Dispose
        _router?.Dispose()
    End Sub
End Class
$vbLabelText   $csharpLabel

Sonra — IronBarcode statik API:

// NuGet: dotnet add package BarCode
using IronBarCode;

public class BarcodeService
{
    // No constructor initialization — license set once at app startup
    // No Dispose — no instance to clean up

    public string[] ReadFile(string path)
    {
        var options = new BarcodeReaderOptions { ExpectMultipleBarcodes = true };
        return BarcodeReader.Read(path, options)
            .Select(r => r.Value)
            .ToArray();
    }
}
// NuGet: dotnet add package BarCode
using IronBarCode;

public class BarcodeService
{
    // No constructor initialization — license set once at app startup
    // No Dispose — no instance to clean up

    public string[] ReadFile(string path)
    {
        var options = new BarcodeReaderOptions { ExpectMultipleBarcodes = true };
        return BarcodeReader.Read(path, options)
            .Select(r => r.Value)
            .ToArray();
    }
}
Imports IronBarCode

Public Class BarcodeService
    ' No constructor initialization — license set once at app startup
    ' No Dispose — no instance to clean up

    Public Function ReadFile(path As String) As String()
        Dim options As New BarcodeReaderOptions With {.ExpectMultipleBarcodes = True}
        Return BarcodeReader.Read(path, options) _
            .Select(Function(r) r.Value) _
            .ToArray()
    End Function
End Class
$vbLabelText   $csharpLabel

Sınıf, yapıcısını, IDisposable uygulamasını ve _router alanını kaybeder. Bu hizmet, DI içinde bir singleton veya yaşam döngüsü hizmeti olarak kaydedilmişse, bu kayıt basitleştirilebilir veya hizmet bir dizi statik metoda dönüşebilir.

Okuma Hızı vs Zaman Aşımı Eşleme

Dynamsoft, kamera kare hızları için optimize edilmiş milisaniyeler cinsinden bir Timeout kullanır. IronBarcode bir ReadingSpeed enum kullanır:

Dynamsoft ayarı IronBarcode eşdeğeri
settings.Timeout = 100 (kamera hattı) Speed = ReadingSpeed.Faster
Düşük zaman aşımı (hız öncelikli) Speed = ReadingSpeed.Balanced
Daha yüksek zaman aşımı (doğruluk öncelikli) Speed = ReadingSpeed.Detailed
Maksimum doğruluk, zaman baskısı yok Speed = ReadingSpeed.ExtremeDetail

İş hacminin 100ms altındaki yanıt süresinden daha önemli olduğu çoğu belge işleme iş akışları için, ReadingSpeed.Balanced doğru varsayılandır:

var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true,
    MaxParallelThreads = 4
};
var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true,
    MaxParallelThreads = 4
};
Dim options As New BarcodeReaderOptions With {
    .Speed = ReadingSpeed.Balanced,
    .ExpectMultipleBarcodes = True,
    .MaxParallelThreads = 4
}
$vbLabelText   $csharpLabel

Yaygın Geçiş Sorunları

BarcodeResultItem.GetText() vs result.Value

Erişim yöntemi bir özellikten değiştirilmiştir:

// Before
string value = item.GetText();

// After
string value = result.Value;
// Before
string value = item.GetText();

// After
string value = result.Value;
' Before
Dim value As String = item.GetText()

' After
Dim value As String = result.Value
$vbLabelText   $csharpLabel

BarcodeResultItem.GetFormatString() vs result.Format

Dynamsoft formatı GetFormatString() üzerinden bir string olarak döndürür. IronBarcode bunu BarcodeEncoding enum olarak result.Format üzerindeki bir enum olarak sunar:

// Before
if (item.GetFormatString() == "QR_CODE")
    Console.WriteLine("Found QR code");

// After
if (result.Format == BarcodeEncoding.QRCode)
    Console.WriteLine("Found QR code");

// For logging without enum comparison — .ToString() works on both
Console.WriteLine($"Format: {result.Format}");
// Before
if (item.GetFormatString() == "QR_CODE")
    Console.WriteLine("Found QR code");

// After
if (result.Format == BarcodeEncoding.QRCode)
    Console.WriteLine("Found QR code");

// For logging without enum comparison — .ToString() works on both
Console.WriteLine($"Format: {result.Format}");
' Before
If item.GetFormatString() = "QR_CODE" Then
    Console.WriteLine("Found QR code")
End If

' After
If result.Format = BarcodeEncoding.QRCode Then
    Console.WriteLine("Found QR code")
End If

' For logging without enum comparison — .ToString() works on both
Console.WriteLine($"Format: {result.Format}")
$vbLabelText   $csharpLabel

Null Sonuçlar vs Boş Koleksiyon

Dynamsoft'un GetDecodedBarcodesResult()'i, barkod bulunamadığında null döndürebilir. IronBarcode boş bir koleksiyon döndürür. Null kontrollerini güncelleyin:

// Before: null check required
CapturedResult result = router.Capture(path, PresetTemplate.PT_READ_BARCODES);
var items = result.GetDecodedBarcodesResult()?.GetItems();
if (items != null && items.Length > 0)
    Process(items[0].GetText());

// After: null-safe but also correct to check Count
var results = BarcodeReader.Read(path);
if (results.Any())
    Process(results.First().Value);
// Before: null check required
CapturedResult result = router.Capture(path, PresetTemplate.PT_READ_BARCODES);
var items = result.GetDecodedBarcodesResult()?.GetItems();
if (items != null && items.Length > 0)
    Process(items[0].GetText());

// After: null-safe but also correct to check Count
var results = BarcodeReader.Read(path);
if (results.Any())
    Process(results.First().Value);
Imports System.Linq

' Before: null check required
Dim result As CapturedResult = router.Capture(path, PresetTemplate.PT_READ_BARCODES)
Dim items = result.GetDecodedBarcodesResult()?.GetItems()
If items IsNot Nothing AndAlso items.Length > 0 Then
    Process(items(0).GetText())
End If

' After: null-safe but also correct to check Count
Dim results = BarcodeReader.Read(path)
If results.Any() Then
    Process(results.First().Value)
End If
$vbLabelText   $csharpLabel

SimplifiedCaptureVisionSettings to BarcodeReaderOptions

GetSimplifiedSettings / UpdateSettings deseni Read'e geçerken BarcodeReaderOptions olur:

// Before
var settings = router.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES);
settings.BarcodeSettings.ExpectedBarcodesCount = 0;
settings.Timeout = 500;
router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings);
var result = router.Capture(path, PresetTemplate.PT_READ_BARCODES);

// After
var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true
};
var results = BarcodeReader.Read(path, options);
// Before
var settings = router.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES);
settings.BarcodeSettings.ExpectedBarcodesCount = 0;
settings.Timeout = 500;
router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings);
var result = router.Capture(path, PresetTemplate.PT_READ_BARCODES);

// After
var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Balanced,
    ExpectMultipleBarcodes = true
};
var results = BarcodeReader.Read(path, options);
' Before
Dim settings = router.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES)
settings.BarcodeSettings.ExpectedBarcodesCount = 0
settings.Timeout = 500
router.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings)
Dim result = router.Capture(path, PresetTemplate.PT_READ_BARCODES)

' After
Dim options As New BarcodeReaderOptions With {
    .Speed = ReadingSpeed.Balanced,
    .ExpectMultipleBarcodes = True
}
Dim results = BarcodeReader.Read(path, options)
$vbLabelText   $csharpLabel

Geçiş Kontrol Listesi

Güncellenmesi gereken tüm Dynamsoft referanslarını bulmak için bu aramaları gerçekleştirin:

grep -r "using Dynamsoft\." --include="*.cs" .
grep -r "LicenseManager.InitLicense\|EnumErrorCode\|EC_OK" --include="*.cs" .
grep -r "new CaptureVisionRouter\|router\.Capture\|PresetTemplate" --include="*.cs" .
grep -r "BarcodeResultItem\|GetDecodedBarcodesResult\|GetFormatString" --include="*.cs" .
grep -r "GetSimplifiedSettings\|UpdateSettings\|SimplifiedCaptureVisionSettings" --include="*.cs" .
grep -r "router\.Dispose\|InitLicenseFromLicenseContent" --include="*.cs" .
grep -r "using Dynamsoft\." --include="*.cs" .
grep -r "LicenseManager.InitLicense\|EnumErrorCode\|EC_OK" --include="*.cs" .
grep -r "new CaptureVisionRouter\|router\.Capture\|PresetTemplate" --include="*.cs" .
grep -r "BarcodeResultItem\|GetDecodedBarcodesResult\|GetFormatString" --include="*.cs" .
grep -r "GetSimplifiedSettings\|UpdateSettings\|SimplifiedCaptureVisionSettings" --include="*.cs" .
grep -r "router\.Dispose\|InitLicenseFromLicenseContent" --include="*.cs" .
SHELL

Her bir eşleşme üzerinde çalışın:

  • using Dynamsoft.*using IronBarCode
  • LicenseManager.InitLicense(key, out errorMsg) + hata kontrolü → IronBarCode.License.LicenseKey = "key"
  • new CaptureVisionRouter() → kaldır (statik API, örnek yok)
  • router.Capture(path, PresetTemplate.PT_READ_BARCODES)BarcodeReader.Read(path)
  • router.Capture(imageData, ...) (ham piksel tamponu) → BarcodeReader.Read(imageBytes)
  • Sayfa başına PDF işleme döngüsü + router.Capture(pageBytes, ...)BarcodeReader.Read(pdfPath)
  • BarcodeResultItem.GetText()result.Value
  • BarcodeResultItem.GetFormatString()result.Format
  • GetSimplifiedSettings(...) + UpdateSettings(...)new BarcodeReaderOptions { ... }
  • router.Dispose() → kaldır
  • LicenseManager.InitLicenseFromLicenseContent(...) → tamamen kaldır
  • PdfiumViewer NuGet paketlerini yalnızca Dynamsoft PDF işleme desteği için eklediyseniz kaldırın
  • Docker/Kubernetes ağ çıkıs kurallarını Dynamsoft lisans uç noktaları için kaldır
  • Dağıtım yapılandırmasında IRONBARCODE_KEY ortam değişkenini ayarla

Sıkça Sorulan Sorular

Neden Dynamsoft Barcode Reader'dan IronBarcode'a geçiş yapmalıyım?

Yaygın nedenler arasında lisanslamanın basitleştirilmesi (SDK + runtime anahtar karmaşıklığının kaldırılması), veri geçiş limitlerinin ortadan kaldırılması, yerel PDF desteği kazanılması, Docker/CI/CD dağıtımının iyileştirilmesi ve üretim kodunda API tekrarlama azalması yer alır.

Dynamsoft API çağrılarını IronBarcode ile nasıl değiştiririm?

Örnek oluşturma ve lisanslama tekrarlamalarını IronBarCode.License.LicenseKey = "anahtar" ile değiştirin. Okuyucu çağrılarını BarcodeReader.Read(yol) ile ve yazıcı çağrılarını BarcodeWriter.CreateBarcode(veri, kodlama) ile değiştirin. Statik yöntemler örnek yönetimi gerektirmez.

Dynamsoft Barcode Reader'dan IronBarcode'a geçiş sırasında ne kadar kod değişiyor?

Çoğu geçiş daha az kod satırıyla sonuçlanır. Lisanslama tekrarlamaları, örnek oluşturucular ve açık format yapılandırması kaldırılır. Temel okuma/yazma işlemleri, daha temiz sonuç nesneleriyle daha kısa IronBarcode eşdeğerlerine dönüştürülür.

Geçiş sırasında hem Dynamsoft Barcode Reader hem de IronBarcode'un yüklü kalması gerekiyor mu?

Hayır. Çoğu geçiş doğrudan değişim yapılır, paralel bir işletim yerine geçer. Bir hizmet sınıfını bir seferde geçirin, NuGet referansını değiştirin ve sonraki sınıfa geçmeden önce başlatma ve API çağrı desenlerini güncelleyin.

IronBarcode için NuGet paketi adı nedir?

Paket 'IronBarCode' (büyük B ve C harfleriyle). 'Install-Package IronBarCode' veya 'dotnet add package IronBarCode' ile kurun. Kodda kullanılan yönerge 'using IronBarCode;' şeklindedir.

IronBarcode, Docker dağıtımını Dynamsoft Barcode Reader'a kıyasla nasıl kolaylaştırır?

IronBarcode, harici SDK dosyaları veya montajlı lisans yapılandırması olmayan bir NuGet paketidir. Docker'da, IRONBARCODE_LICENSE_KEY ortam değişkenini ayarlayın ve paket lisans doğrulamasını başlangıçta kendi kendine yapar.

IronBarcode, Dynamsoft'tan göç ettikten sonra tüm barkod formatlarını otomatik olarak algılıyor mu?

Evet. IronBarcode, desteklenen tüm formatlardaki sembolojiyi otomatik olarak algılar. Açık BarcodeTypes sayımı gerekli değildir. Format zaten biliniyorsa ve performans önemliyse, BarcodeReaderOptions arama alanını optimize etmek için sınırlamayı sağlar.

IronBarcode, ayrı bir kütüphane olmadan PDF'lerden barkod okuyabiliyor mu?

Evet. BarcodeReader.Read("document.pdf") PDF dosyalarını yerel olarak işlemler. Sonuçlar her barkod için SayfaNumarası, Format, Değer ve Güven içerir. Harici bir PDF render adımı gerekmez.

IronBarcode, paralel barkod işlemeyi nasıl yönetiyor?

IronBarcode'un statik yöntemleri durumsuz ve thread-safe'dir. Dağıtılmış dosya listeleri üzerinde per-thread örnek yönetimi olmadan doğrudan Parallel.ForEach kullanın. BarcodeReaderOptions.MaxParallelThreads, iç thread bütçesini kontrol eder.

Dynamsoft Barcode Reader'dan IronBarcode'a geçiş yaparken hangi sonuç özellikleri değişiyor?

Yaygın yeniden adlandırmalar: BarcodeValue, Value olur; BarcodeType, Format olur. IronBarcode sonuçları ayrıca Güven ve SayfaNumarası ekler. Çözüm çapında arama-değiştirme, mevcut sonuç işleme kodundaki yeniden adlandırmaları ele alır.

Bir CI/CD hattında IronBarcode lisanslamasını nasıl ayarlayabilirim?

IRONBARCODE_LICENSE_KEY'i bir boru hattı sırrı olarak saklayın ve uygulama başlangıç kodunda IronBarCode.License.LicenseKey olarak atayın. Bir sır, geliştirme, test, aşama ve üretim dahil olmak üzere tüm ortamları kapsar.

IronBarcode, özel biçimlendirmeye sahip QR kodu üretimini destekliyor mu?

Evet. QRCodeWriter.CreateQrCode() özelleştirilmiş renkler için ChangeBarCodeColor(), logo yerleştirme için AddBrandLogo(), yapılandırılabilir hata düzeltme seviyeleri ve PNG, JPG, PDF ve akış dahil birden çok çıktı formatını destekler.

Curtis Chau
Teknik Yazar

Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapı...

Daha Fazla Oku

Iron Destek Ekibi

Haftada 5 gün, 24 saat çevrimiçiyiz.
Sohbet
E-posta
Beni Ara