フッターコンテンツにスキップ
ビデオ

System.Drawingオブジェクトからバーコードを読む方法

Cloudmersive Barcode APIからIronBarcodeへの移行

これは、 .NETバーコードの歴史上、最もシンプルな移行事例です。 HTTPクライアントを削除してください。 NuGetパッケージを追加します。 APIキー管理を削除します。 残りは検索と置換です。

Cloudmersive for .NET SDKは生成されたREST APIクライアントで、HttpClient呼び出しの薄いラッパーです。 アプリケーション内のCloudmersive固有のコードはすべて、そのクライアントの設定、そのクライアントを介した呼び出し、またはネットワーク要求が失敗した場合のエラー処理のいずれかです。 IronBarcodeはネットワークに依存せずローカルでバーコードを処理するため、そのようなインフラストラクチャは一切不要です。


クイックスタート:3つのステップ

ステップ1:パッケージを交換する

dotnet remove package Cloudmersive.APIClient.NET.Barcode
dotnet add package BarCode
dotnet remove package Cloudmersive.APIClient.NET.Barcode
dotnet add package BarCode
SHELL

ステップ2:名前空間の置換

// Remove these
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

// Add this
using IronBarCode;
// Remove these
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

// Add this
using IronBarCode;
Imports IronBarCode
$vbLabelText   $csharpLabel

ステップ3:APIキー設定をライセンスキーに置き換える

// Remove this
Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");

// Replace with this — set once at application startup
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// Remove this
Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");

// Replace with this — set once at application startup
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
' Remove this
Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY")

' Replace with this — set once at application startup
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

ASP.NET Coreアプリケーションでは、ライセンスキーをProgram.csに配置します:

using IronBarCode;

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

var builder = WebApplication.CreateBuilder(args);
// ... rest of startup
using IronBarCode;

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

var builder = WebApplication.CreateBuilder(args);
// ... rest of startup
Imports IronBarCode

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

Dim builder = WebApplication.CreateBuilder(args)
' ... rest of startup
$vbLabelText   $csharpLabel

費用:これまで使っていた金額とこれから使う金額

移行する前に、Cloudmersiveとの連携に実際にかかる費用を計算しておく価値があります。 計算は簡単だ。

1日の摂取量 月間リクエスト Cloudmersiveティア IronBarcode (1回限り)
1日100ドル 約3,000 基本$19.99/月 $749
1,000/日 約30,000 ビジネスプレミアム$99.99/月 $749
1日5,000 約15万 中規模ビジネス$499.99/月 $749
1日10,000 約30万 エンタープライズ(カスタム) $749
1日25,000人 約75万 エンタープライズ(カスタム) 1,499ドル(Plus、開発者3名)

Cloudmersiveの料金が月$63以上である場合、IronBarcodeのLiteライセンスは最初の1年以内に元が取れます。 元が取れた後、IronBarcodeは更新不要の永続ライセンスで、1リクエストあたりの料金もありません。


コード移行の例

QRコード生成

Cloudmersiveで最も一般的な生成呼び出しは、 IronBarcodeに直接対応しています。

以前(Cloudmersive):

using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");

var apiInstance = new GenerateBarcodeApi();

byte[] result = apiInstance.GenerateBarcodeQRCode("https://example.com");
File.WriteAllBytes("qr.png", result);
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");

var apiInstance = new GenerateBarcodeApi();

byte[] result = apiInstance.GenerateBarcodeQRCode("https://example.com");
File.WriteAllBytes("qr.png", result);
Imports Cloudmersive.APIClient.NET.Barcode.Api
Imports Cloudmersive.APIClient.NET.Barcode.Client

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY")

Dim apiInstance As New GenerateBarcodeApi()

Dim result As Byte() = apiInstance.GenerateBarcodeQRCode("https://example.com")
File.WriteAllBytes("qr.png", result)
$vbLabelText   $csharpLabel

(IronBarcode)後:

using IronBarCode;

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

byte[] result = QRCodeWriter.CreateQrCode("https://example.com", 500)
    .ToPngBinaryData();
File.WriteAllBytes("qr.png", result);

// Or save directly
QRCodeWriter.CreateQrCode("https://example.com", 500)
    .SaveAsPng("qr.png");
using IronBarCode;

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

byte[] result = QRCodeWriter.CreateQrCode("https://example.com", 500)
    .ToPngBinaryData();
File.WriteAllBytes("qr.png", result);

// Or save directly
QRCodeWriter.CreateQrCode("https://example.com", 500)
    .SaveAsPng("qr.png");
Imports IronBarCode

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

Dim result As Byte() = QRCodeWriter.CreateQrCode("https://example.com", 500).ToPngBinaryData()
File.WriteAllBytes("qr.png", result)

' Or save directly
QRCodeWriter.CreateQrCode("https://example.com", 500).SaveAsPng("qr.png")
$vbLabelText   $csharpLabel

コード128生成

以前(Cloudmersive):

using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");
var apiInstance = new GenerateBarcodeApi();

byte[] result = apiInstance.GenerateBarcodeCode128("SHIP-2024031500428");
File.WriteAllBytes("barcode.png", result);
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");
var apiInstance = new GenerateBarcodeApi();

byte[] result = apiInstance.GenerateBarcodeCode128("SHIP-2024031500428");
File.WriteAllBytes("barcode.png", result);
Imports Cloudmersive.APIClient.NET.Barcode.Api
Imports Cloudmersive.APIClient.NET.Barcode.Client

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY")
Dim apiInstance As New GenerateBarcodeApi()

Dim result As Byte() = apiInstance.GenerateBarcodeCode128("SHIP-2024031500428")
File.WriteAllBytes("barcode.png", result)
$vbLabelText   $csharpLabel

(IronBarcode)後:

using IronBarCode;

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

BarcodeWriter.CreateBarcode("SHIP-2024031500428", BarcodeEncoding.Code128)
    .SaveAsPng("barcode.png");

// Or get bytes directly
byte[] result = BarcodeWriter.CreateBarcode("SHIP-2024031500428", BarcodeEncoding.Code128)
    .ToPngBinaryData();
using IronBarCode;

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

BarcodeWriter.CreateBarcode("SHIP-2024031500428", BarcodeEncoding.Code128)
    .SaveAsPng("barcode.png");

// Or get bytes directly
byte[] result = BarcodeWriter.CreateBarcode("SHIP-2024031500428", BarcodeEncoding.Code128)
    .ToPngBinaryData();
Imports IronBarCode

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

BarcodeWriter.CreateBarcode("SHIP-2024031500428", BarcodeEncoding.Code128) _
    .SaveAsPng("barcode.png")

' Or get bytes directly
Dim result As Byte() = BarcodeWriter.CreateBarcode("SHIP-2024031500428", BarcodeEncoding.Code128) _
    .ToPngBinaryData()
$vbLabelText   $csharpLabel

バーコード読み取り

以前(Cloudmersive):

using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");
var scanApi = new BarcodeScanApi();

using (var stream = File.OpenRead("barcode.png"))
{
    var result = scanApi.BarcodeScanImage(stream);
    if (result.Successful == true)
    {
        Console.WriteLine($"Value: {result.RawText}");
        Console.WriteLine($"Type: {result.BarcodeType}");
    }
}
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");
var scanApi = new BarcodeScanApi();

using (var stream = File.OpenRead("barcode.png"))
{
    var result = scanApi.BarcodeScanImage(stream);
    if (result.Successful == true)
    {
        Console.WriteLine($"Value: {result.RawText}");
        Console.WriteLine($"Type: {result.BarcodeType}");
    }
}
Imports Cloudmersive.APIClient.NET.Barcode.Api
Imports Cloudmersive.APIClient.NET.Barcode.Client

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY")
Dim scanApi As New BarcodeScanApi()

Using stream = File.OpenRead("barcode.png")
    Dim result = scanApi.BarcodeScanImage(stream)
    If result.Successful = True Then
        Console.WriteLine($"Value: {result.RawText}")
        Console.WriteLine($"Type: {result.BarcodeType}")
    End If
End Using
$vbLabelText   $csharpLabel

(IronBarcode)後:

using IronBarCode;

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

var results = BarcodeReader.Read("barcode.png");
var result = results.First();
Console.WriteLine($"Value: {result.Value}");
Console.WriteLine($"Type: {result.Format}");
using IronBarCode;

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

var results = BarcodeReader.Read("barcode.png");
var result = results.First();
Console.WriteLine($"Value: {result.Value}");
Console.WriteLine($"Type: {result.Format}");
Imports IronBarCode

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

Dim results = BarcodeReader.Read("barcode.png")
Dim result = results.First()
Console.WriteLine($"Value: {result.Value}")
Console.WriteLine($"Type: {result.Format}")
$vbLabelText   $csharpLabel

非同期バーコード読み取り

Cloudmersiveの統合で非同期APIを使用している場合:

以前(Cloudmersive):

using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");
var scanApi = new BarcodeScanApi();

using (var stream = File.OpenRead("barcode.png"))
{
    var result = await scanApi.BarcodeScanImageAsync(stream);
    return result.Successful == true ? result.RawText : null;
}
using Cloudmersive.APIClient.NET.Barcode.Api;
using Cloudmersive.APIClient.NET.Barcode.Client;

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY");
var scanApi = new BarcodeScanApi();

using (var stream = File.OpenRead("barcode.png"))
{
    var result = await scanApi.BarcodeScanImageAsync(stream);
    return result.Successful == true ? result.RawText : null;
}
Imports Cloudmersive.APIClient.NET.Barcode.Api
Imports Cloudmersive.APIClient.NET.Barcode.Client

Configuration.Default.ApiKey.Add("Apikey", "YOUR-CLOUDMERSIVE-API-KEY")
Dim scanApi As New BarcodeScanApi()

Using stream = File.OpenRead("barcode.png")
    Dim result = Await scanApi.BarcodeScanImageAsync(stream)
    Return If(result.Successful = True, result.RawText, Nothing)
End Using
$vbLabelText   $csharpLabel

(IronBarcode)後:

using IronBarCode;

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

// IronBarcode is synchronous; wrap in Task.Run to free the calling thread for CPU-bound work
var results = await Task.Run(() => BarcodeReader.Read("barcode.png"));
return results.FirstOrDefault()?.Value;
using IronBarCode;

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

// IronBarcode is synchronous; wrap in Task.Run to free the calling thread for CPU-bound work
var results = await Task.Run(() => BarcodeReader.Read("barcode.png"));
return results.FirstOrDefault()?.Value;
Imports IronBarCode

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

' IronBarcode is synchronous; wrap in Task.Run to free the calling thread for CPU-bound work
Dim results = Await Task.Run(Function() BarcodeReader.Read("barcode.png"))
Return results.FirstOrDefault()?.Value
$vbLabelText   $csharpLabel

PDFファイルからバーコードを読み取る

CloudmersiveはネイティブのPDFサポートを提供していません。 既存のコードでスキャン前にPDFから画像を抽出している場合は、そのパイプライン全体をIronBarcodeの単一の呼び出しに置き換えてください。

以前(Cloudmersive - PDFの抽出は別途必要):

// Requires a separate PDF library to extract pages as images,
// then one Cloudmersive API call per extracted page image.
var scanApi = new BarcodeScanApi();
foreach (var pageImagePath in ExtractPdfPages("document.pdf"))
{
    using var stream = File.OpenRead(pageImagePath);
    var result = await scanApi.BarcodeScanImageAsync(stream);
    if (result.Successful == true)
    {
        Console.WriteLine($"Found: {result.RawText}");
    }
}
// Requires a separate PDF library to extract pages as images,
// then one Cloudmersive API call per extracted page image.
var scanApi = new BarcodeScanApi();
foreach (var pageImagePath in ExtractPdfPages("document.pdf"))
{
    using var stream = File.OpenRead(pageImagePath);
    var result = await scanApi.BarcodeScanImageAsync(stream);
    if (result.Successful == true)
    {
        Console.WriteLine($"Found: {result.RawText}");
    }
}
Imports System.IO
Imports Cloudmersive.APIClient.NET.BarcodeScan

' Requires a separate PDF library to extract pages as images,
' then one Cloudmersive API call per extracted page image.
Dim scanApi As New BarcodeScanApi()
For Each pageImagePath In ExtractPdfPages("document.pdf")
    Using stream As FileStream = File.OpenRead(pageImagePath)
        Dim result = Await scanApi.BarcodeScanImageAsync(stream)
        If result.Successful = True Then
            Console.WriteLine($"Found: {result.RawText}")
        End If
    End Using
Next
$vbLabelText   $csharpLabel

(IronBarcode)後:

using IronBarCode;

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

// One call — all pages, all barcodes, no image extraction step
var results = BarcodeReader.Read("document.pdf");
foreach (var result in results)
{
    Console.WriteLine($"Page {result.PageNumber}: {result.Value}");
}
using IronBarCode;

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

// One call — all pages, all barcodes, no image extraction step
var results = BarcodeReader.Read("document.pdf");
foreach (var result in results)
{
    Console.WriteLine($"Page {result.PageNumber}: {result.Value}");
}
Imports IronBarCode

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

' One call — all pages, all barcodes, no image extraction step
Dim results = BarcodeReader.Read("document.pdf")
For Each result In results
    Console.WriteLine($"Page {result.PageNumber}: {result.Value}")
Next
$vbLabelText   $csharpLabel

複数バーコード検出

複数のバーコードを含む文書をスキャンするコードをお持ちの場合:

以前(Cloudmersive - 複数回の呼び出しが必要):

// Cloudmersive returns one barcode per scan — multiple calls for multiple barcodes
var scanApi = new BarcodeScanApi();
var barcodeValues = new List<string>();

foreach (var croppedRegion in CropBarcodeRegions("invoice.png"))
{
    using var stream = new MemoryStream(croppedRegion);
    var result = await scanApi.BarcodeScanImageAsync(stream);
    if (result.Successful == true)
        barcodeValues.Add(result.RawText);
}
// Cloudmersive returns one barcode per scan — multiple calls for multiple barcodes
var scanApi = new BarcodeScanApi();
var barcodeValues = new List<string>();

foreach (var croppedRegion in CropBarcodeRegions("invoice.png"))
{
    using var stream = new MemoryStream(croppedRegion);
    var result = await scanApi.BarcodeScanImageAsync(stream);
    if (result.Successful == true)
        barcodeValues.Add(result.RawText);
}
Imports System.IO
Imports System.Collections.Generic
Imports System.Threading.Tasks

' Cloudmersive returns one barcode per scan — multiple calls for multiple barcodes
Dim scanApi As New BarcodeScanApi()
Dim barcodeValues As New List(Of String)()

For Each croppedRegion In CropBarcodeRegions("invoice.png")
    Using stream As New MemoryStream(croppedRegion)
        Dim result = Await scanApi.BarcodeScanImageAsync(stream)
        If result.Successful = True Then
            barcodeValues.Add(result.RawText)
        End If
    End Using
Next
$vbLabelText   $csharpLabel

(IronBarcode)後:

using IronBarCode;

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

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

// One call — returns all barcodes in the image
var results = BarcodeReader.Read("invoice.png", options);
var barcodeValues = results.Select(r => r.Value).ToList();
using IronBarCode;

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

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

// One call — returns all barcodes in the image
var results = BarcodeReader.Read("invoice.png", options);
var barcodeValues = results.Select(r => r.Value).ToList();
Imports IronBarCode

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

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

' One call — returns all barcodes in the image
Dim results = BarcodeReader.Read("invoice.png", options)
Dim barcodeValues = results.Select(Function(r) r.Value).ToList()
$vbLabelText   $csharpLabel

不要になったインフラの撤去

これは移行作業の中で、新規に記述するコードよりも削除するコードの方が多くなるような部分です。

HTTP例外処理を削除する

Cloudmersiveの操作は、ネットワークエラー、HTTP 4xx/5xx応答、タイムアウト例外によって失敗する可能性があります。 これは通常、 IronBarcodeが必要としないtry/catch構造を生み出します。

// Remove all of this
try
{
    var result = await scanApi.BarcodeScanImageAsync(stream);
    // ...
}
catch (ApiException ex) when (ex.ErrorCode == 429)
{
    // Rate limited — wait and retry
    await Task.Delay(TimeSpan.FromSeconds(2));
    // retry logic...
}
catch (ApiException ex) when (ex.ErrorCode == 503)
{
    // Service unavailable — Cloudmersive is down
    _logger.LogError("Cloudmersive unavailable: {Message}", ex.Message);
    throw;
}
catch (HttpRequestException ex)
{
    // Network error
    _logger.LogError("Network failure: {Message}", ex.Message);
    throw;
}
catch (TaskCanceledException)
{
    // Timeout
    _logger.LogError("Cloudmersive request timed out");
    throw;
}
// Remove all of this
try
{
    var result = await scanApi.BarcodeScanImageAsync(stream);
    // ...
}
catch (ApiException ex) when (ex.ErrorCode == 429)
{
    // Rate limited — wait and retry
    await Task.Delay(TimeSpan.FromSeconds(2));
    // retry logic...
}
catch (ApiException ex) when (ex.ErrorCode == 503)
{
    // Service unavailable — Cloudmersive is down
    _logger.LogError("Cloudmersive unavailable: {Message}", ex.Message);
    throw;
}
catch (HttpRequestException ex)
{
    // Network error
    _logger.LogError("Network failure: {Message}", ex.Message);
    throw;
}
catch (TaskCanceledException)
{
    // Timeout
    _logger.LogError("Cloudmersive request timed out");
    throw;
}
Imports System
Imports System.Threading.Tasks

' Remove all of this
Try
    Dim result = Await scanApi.BarcodeScanImageAsync(stream)
    ' ...
Catch ex As ApiException When ex.ErrorCode = 429
    ' Rate limited — wait and retry
    Await Task.Delay(TimeSpan.FromSeconds(2))
    ' retry logic...
Catch ex As ApiException When ex.ErrorCode = 503
    ' Service unavailable — Cloudmersive is down
    _logger.LogError("Cloudmersive unavailable: {Message}", ex.Message)
    Throw
Catch ex As HttpRequestException
    ' Network error
    _logger.LogError("Network failure: {Message}", ex.Message)
    Throw
Catch ex As TaskCanceledException
    ' Timeout
    _logger.LogError("Cloudmersive request timed out")
    Throw
End Try
$vbLabelText   $csharpLabel

IronBarcodeはネットワーク例外をスローしません。 バーコードが入力からデコードできない場合、それはインフラストラクチャの問題ではなく、コンテンツの問題としてBarcodeExceptionがスローされます。 簡略化されたエラー処理:

using IronBarCode;

var results = BarcodeReader.Read("barcode.png");
if (!results.Any())
{
    _logger.LogWarning("No barcode detected in image");
}
using IronBarCode;

var results = BarcodeReader.Read("barcode.png");
if (!results.Any())
{
    _logger.LogWarning("No barcode detected in image");
}
Imports IronBarCode

Dim results = BarcodeReader.Read("barcode.png")
If Not results.Any() Then
    _logger.LogWarning("No barcode detected in image")
End If
$vbLabelText   $csharpLabel

再試行ロジックを削除

Cloudmersiveとの連携に再試行ポリシー(Polly、カスタム再試行ループ、指数バックオフなど)が含まれている場合は、それらを完全に削除してください。

// Remove retry infrastructure
// var retryPolicy = Policy
//     .Handle<ApiException>()
//     .WaitAndRetryAsync(3, retryAttempt =>
//         TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

// IronBarcode — no retry needed
var results = BarcodeReader.Read("barcode.png");
// Remove retry infrastructure
// var retryPolicy = Policy
//     .Handle<ApiException>()
//     .WaitAndRetryAsync(3, retryAttempt =>
//         TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));

// IronBarcode — no retry needed
var results = BarcodeReader.Read("barcode.png");
' Remove retry infrastructure
' Dim retryPolicy = Policy _
'     .Handle(Of ApiException)() _
'     .WaitAndRetryAsync(3, Function(retryAttempt) _
'         TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))

' IronBarcode — no retry needed
Dim results = BarcodeReader.Read("barcode.png")
$vbLabelText   $csharpLabel

レート制限追跡を解除する

コードがCloudmersiveの月間クォータ内に収まるようにAPI呼び出し回数を追跡している場合:

// Remove quota tracking
// private static int _monthlyCallCount = 0;
// private const int MonthlyLimit = 30000;
//
// if (Interlocked.Increment(ref _monthlyCallCount) > MonthlyLimit)
//     throw new InvalidOperationException("Monthly Cloudmersive quota exceeded");

// IronBarcode — no quota
var results = BarcodeReader.Read("barcode.png");
// Remove quota tracking
// private static int _monthlyCallCount = 0;
// private const int MonthlyLimit = 30000;
//
// if (Interlocked.Increment(ref _monthlyCallCount) > MonthlyLimit)
//     throw new InvalidOperationException("Monthly Cloudmersive quota exceeded");

// IronBarcode — no quota
var results = BarcodeReader.Read("barcode.png");
' Remove quota tracking
' Private Shared _monthlyCallCount As Integer = 0
' Private Const MonthlyLimit As Integer = 30000
'
' If Interlocked.Increment(_monthlyCallCount) > MonthlyLimit Then
'     Throw New InvalidOperationException("Monthly Cloudmersive quota exceeded")

' IronBarcode — no quota
Dim results = BarcodeReader.Read("barcode.png")
$vbLabelText   $csharpLabel

ネットワークタイムアウト設定を削除する

Cloudmersiveのクライアントには、タイムアウト設定が含まれていることが多い。 削除してください:

// Remove timeout configuration
// Configuration.Default.Timeout = 30000; // 30 second timeout
// Configuration.Default.ConnectionTimeout = 5000;

// IronBarcode has no network timeout — no network
// Remove timeout configuration
// Configuration.Default.Timeout = 30000; // 30 second timeout
// Configuration.Default.ConnectionTimeout = 5000;

// IronBarcode has no network timeout — no network
' Remove timeout configuration
' Configuration.Default.Timeout = 30000 ' 30 second timeout
' Configuration.Default.ConnectionTimeout = 5000

' IronBarcode has no network timeout — no network
$vbLabelText   $csharpLabel

APIキーローテーションを削除する

アプリケーションがAPIキーを定期的にローテーションするか、シークレット管理に保存する場合:

// Simplify this pattern
// private string GetCloudmersiveApiKey() =>
//     _secretManager.GetSecret("cloudmersive-api-key-current");
//
// Configuration.Default.ApiKey["Apikey"] = GetCloudmersiveApiKey();

// IronBarcode — set once at startup
IronBarCode.License.LicenseKey = _configuration["IronBarcode:LicenseKey"];
// or literal: "YOUR-LICENSE-KEY"
// Simplify this pattern
// private string GetCloudmersiveApiKey() =>
//     _secretManager.GetSecret("cloudmersive-api-key-current");
//
// Configuration.Default.ApiKey["Apikey"] = GetCloudmersiveApiKey();

// IronBarcode — set once at startup
IronBarCode.License.LicenseKey = _configuration["IronBarcode:LicenseKey"];
// or literal: "YOUR-LICENSE-KEY"
' Simplify this pattern
' Private Function GetCloudmersiveApiKey() As String
'     Return _secretManager.GetSecret("cloudmersive-api-key-current")
' End Function
'
' Configuration.Default.ApiKey("Apikey") = GetCloudmersiveApiKey()

' IronBarcode — set once at startup
IronBarCode.License.LicenseKey = _configuration("IronBarcode:LicenseKey")
' or literal: "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

よくある移行の問題

Cloudmersiveが生成のためにbyte[]を返しました

Cloudmersiveの生成メソッドはbyte[]を直接返します。 IronBarcodeは、より多くのオプションを提供するGeneratedBarcodeオブジェクトを返します。

// Cloudmersive returned byte[] directly
byte[] cloudmersiveResult = apiInstance.GenerateBarcodeQRCode("data");

// IronBarcode — call ToPngBinaryData() for the equivalent byte[]
byte[] ironBarcodeResult = BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode)
    .ToPngBinaryData();

// Or save directly (often simpler)
BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode)
    .SaveAsPng("output.png");

// Or get other formats
byte[] jpegBytes = BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode)
    .ToJpegBinaryData();
// Cloudmersive returned byte[] directly
byte[] cloudmersiveResult = apiInstance.GenerateBarcodeQRCode("data");

// IronBarcode — call ToPngBinaryData() for the equivalent byte[]
byte[] ironBarcodeResult = BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode)
    .ToPngBinaryData();

// Or save directly (often simpler)
BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode)
    .SaveAsPng("output.png");

// Or get other formats
byte[] jpegBytes = BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode)
    .ToJpegBinaryData();
Imports Cloudmersive.APIClient
Imports IronBarCode

' Cloudmersive returned byte() directly
Dim cloudmersiveResult As Byte() = apiInstance.GenerateBarcodeQRCode("data")

' IronBarcode — call ToPngBinaryData() for the equivalent byte()
Dim ironBarcodeResult As Byte() = BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode) _
    .ToPngBinaryData()

' Or save directly (often simpler)
BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode) _
    .SaveAsPng("output.png")

' Or get other formats
Dim jpegBytes As Byte() = BarcodeWriter.CreateBarcode("data", BarcodeEncoding.QRCode) _
    .ToJpegBinaryData()
$vbLabelText   $csharpLabel

Cloudmersive Reading が JSON レスポンス モデルを返しました

Cloudmersiveのスキャン結果は、BarcodeTypeなどのプロパティを持つレスポンスモデルです。 IronBarcodeは型付きの結果オブジェクトを返します。

// Cloudmersive result model
if (cloudmersiveResult.Successful == true)
{
    string value = cloudmersiveResult.RawText;
    string type = cloudmersiveResult.BarcodeType;
}

// IronBarcode result — use .Value and .Format directly
var results = BarcodeReader.Read("barcode.png");
if (results.Any())
{
    string value = results.First().Value;
    string format = results.First().Format.ToString();
}
// Cloudmersive result model
if (cloudmersiveResult.Successful == true)
{
    string value = cloudmersiveResult.RawText;
    string type = cloudmersiveResult.BarcodeType;
}

// IronBarcode result — use .Value and .Format directly
var results = BarcodeReader.Read("barcode.png");
if (results.Any())
{
    string value = results.First().Value;
    string format = results.First().Format.ToString();
}
' Cloudmersive result model
If cloudmersiveResult.Successful = True Then
    Dim value As String = cloudmersiveResult.RawText
    Dim type As String = cloudmersiveResult.BarcodeType
End If

' IronBarcode result — use .Value and .Format directly
Dim results = BarcodeReader.Read("barcode.png")
If results.Any() Then
    Dim value As String = results.First().Value
    Dim format As String = results.First().Format.ToString()
End If
$vbLabelText   $csharpLabel

複数のCloudmersive APIインスタンスタイプ

Cloudmersiveは生成とスキャンをBarcodeScanApiインスタンスに分けています。 IronBarcodeは静的クラスを使用するため、インスタンスは不要です。

// Cloudmersive — two separate API instances
var generateApi = new GenerateBarcodeApi();
var scanApi = new BarcodeScanApi();

// IronBarcode — static, no instances
// BarcodeWriter for generation
// BarcodeReader for reading
// QRCodeWriter for QR codes specifically
// Cloudmersive — two separate API instances
var generateApi = new GenerateBarcodeApi();
var scanApi = new BarcodeScanApi();

// IronBarcode — static, no instances
// BarcodeWriter for generation
// BarcodeReader for reading
// QRCodeWriter for QR codes specifically
' Cloudmersive — two separate API instances
Dim generateApi As New GenerateBarcodeApi()
Dim scanApi As New BarcodeScanApi()

' IronBarcode — static, no instances
' BarcodeWriter for generation
' BarcodeReader for reading
' QRCodeWriter for QR codes specifically
$vbLabelText   $csharpLabel

移行チェックリスト

移行前と移行後にコードベースで以下の検索を実行して、Cloudmersiveへの参照がすべて検出されていることを確認してください。

# Find all Cloudmersive references
grep -r "Cloudmersive" --include="*.cs" .
grep -r "GenerateBarcodeApi" --include="*.cs" .
grep -r "BarcodeScanApi" --include="*.cs" .
grep -r "Configuration.Default.ApiKey" --include="*.cs" .
grep -r '"Apikey"' --include="*.cs" .
grep -r "GenerateBarcodeQRCode" --include="*.cs" .
grep -r "GenerateBarcodeCode128" --include="*.cs" .
grep -r "BarcodeScanImage" --include="*.cs" .
grep -r "cloudmersive" --include="*.csproj" .
grep -r "cloudmersive" --include="*.json" .
# Find all Cloudmersive references
grep -r "Cloudmersive" --include="*.cs" .
grep -r "GenerateBarcodeApi" --include="*.cs" .
grep -r "BarcodeScanApi" --include="*.cs" .
grep -r "Configuration.Default.ApiKey" --include="*.cs" .
grep -r '"Apikey"' --include="*.cs" .
grep -r "GenerateBarcodeQRCode" --include="*.cs" .
grep -r "GenerateBarcodeCode128" --include="*.cs" .
grep -r "BarcodeScanImage" --include="*.cs" .
grep -r "cloudmersive" --include="*.csproj" .
grep -r "cloudmersive" --include="*.json" .
SHELL

移行後、すべての検索結果はゼロになるはずです。 次に、 IronBarcodeが正しく参照されていることを確認します。

grep -r "IronBarCode" --include="*.cs" .
grep -r "BarcodeReader" --include="*.cs" .
grep -r "BarcodeWriter" --include="*.cs" .
grep -r "IronBarCode" --include="*.cs" .
grep -r "BarcodeReader" --include="*.cs" .
grep -r "BarcodeWriter" --include="*.cs" .
SHELL

構成チェックリスト

  • すべてのCloudmersive.APIClient.NET.Barcodeを削除します
  • Cloudmersive APIキーをappsettings.json、環境変数、および秘密ストアから削除します IronBarcode NuGetパッケージを追加する
  • アプリケーション起動時にIronBarCode.License.LicenseKey初期化を追加します
  • Cloudmersive コールの再試行ポリシーとサーキットブレーカーを削除します
  • レート制限追跡コードを削除する ネットワークタイムアウト設定を削除します

テストチェックリスト

移行完了後:

  • QRコード生成結果が有効でスキャン可能な出力であることを確認する
  • Code128およびその他のリニアバーコード生成を検証する
  • 一般的な画像フォーマット(PNG、JPEG、BMP)からのバーコード読み取りを検証する PDF文書を処理する場合は、PDFの読み取りテストを行ってください。
  • 該当する場合は、複数バーコード検出をテストする
  • ネットワークトラフィックにCloudmersive API呼び出しが表示されないことを確認する
  • インターネット接続がない状態でアプリケーションが正しく動作することを確認してください。

移行後に得られるもの

コスト削減に加え、この移行によって運用上の懸念事項が一掃される。

ネットワークに依存するバーコード処理はもう必要ありません。Cloudmersiveの可用性、インターネット接続の品質、ネットワーク遅延の急上昇に関係なく、ドキュメント処理パイプラインは正常に動作します。

割り当て量の管理はもう不要です。月末の文書量急増による予期せぬ超過や処理エラーも発生しません。

ネットワークからデータが流出することはもうありません。機密性の高い顧客情報、財務情報、または健康情報を含むバーコード画像は、お客様のインフラストラクチャ上に保持されます。

コードがよりシンプルになりました。本番環境のCloudmersive統合に必要な再試行インフラストラクチャ、タイムアウト処理、HTTP例外管理は不要になりました。 その代わりに、直接的なメソッド呼び出しが行われる。

移行は機械的なものである。 そのメリットは構造的なものであり、外部ネットワークサービスを必要としないワークフローから、そのサービスへの依存を排除​​できるという点にある。

よくある質問

なぜCloudmersive BarCode APIからIronBarcodeに移行する必要があるのですか?

一般的な理由としては、ライセンスの簡素化(SDK + ランタイムキーの複雑さの排除)、スループット制限の排除、ネイティブPDFサポートの獲得、Docker/CI/CDデプロイの改善、プロダクションコード内のAPI定型文の削減などが挙げられます。

CloudmersiveのAPIコールをIronBarcodeに置き換えるには?

インスタンスの作成とライセンスの定型文をIronBarCode.License.LicenseKey = "key "に置き換えてください。リーダー・コールをBarcodeReader.Read(path)に、ライター・コールをBarcodeWriter.CreateBarcode(data, encoding)に置き換えてください。静的メソッドはインスタンス管理を必要としません。

Cloudmersive BarCode APIからIronBarcodeに移行する場合、コードはどのくらい変更されますか?

ほとんどのマイグレーションでは、コード行数は少なくなります。ライセンスの定型文、インスタンス・コンストラクタ、明示的なフォーマット設定が削除されます。コアとなる読み取り/書き込み操作は、より短いIronBarcodeに対応し、よりきれいな結果オブジェクトが得られます。

移行中にCloudmersive BarCode APIとIronBarcodeの両方をインストールしておく必要がありますか?

ほとんどのマイグレーションは、並列操作ではなく、直接置き換えです。一度に1つのサービスクラスを移行し、NuGet参照を置き換え、インスタンス化とAPI呼び出しパターンを更新してから次のクラスに移行します。

IronBarcodeのNuGetパッケージ名は何ですか?

パッケージは'IronBarcode'(大文字のBとC)です。Install-Package IronBarcode'または'dotnet add package IronBarcode'でインストールしてください。コード中のusingディレクティブは'using IronBarcode;'である。

IronBarcodeはCloudmersive BarCode APIと比較して、どのようにDockerデプロイメントを簡素化しますか?

IronBarcodeは外部SDKファイルやマウントされたライセンス設定のないNuGetパッケージです。Dockerでは、IRONBARCODE_LICENSE_KEY環境変数を設定すると、パッケージが起動時にライセンス検証を処理します。

Cloudmersiveから移行した後、IronBarcodeはすべてのバーコードフォーマットを自動的に検出しますか?

IronBarcodeは、サポートされているすべてのフォーマットのシンボルを自動検出します。明示的なBarcodeTypesの列挙は必要ありません。フォーマットが既に知られていて、パフォーマンスが重要な場合、BarcodeReaderOptionsは最適化として検索空間を制限することができます。

IronBarcodeは別のライブラリなしでPDFからバーコードを読み取ることができますか?

BarcodeReader.Read("document.pdf")は、PDFファイルをネイティブに処理します。結果には、見つかった各バーコードの PageNumber、Format、Value、および Confidence が含まれます。外部のPDFレンダリングステップは必要ありません。

IronBarcodeはどのようにパラレルバーコード処理を行うのですか?

IronBarcodeの静的メソッドはステートレスでスレッドセーフです。Parallel.ForEachをスレッドごとのインスタンス管理なしにファイルリスト上で直接使用します。BarcodeReaderOptions.MaxParallelThreadsは内部のスレッドバジェットを制御します。

Cloudmersive BarCode APIからIronBarcodeに移行すると、どのような結果のプロパティが変更されますか?

一般的なリネーム:BarcodeValueはValueに、BarcodeTypeはFormatに。IronBarcodeの結果にはConfidenceとPageNumberも追加されます。ソリューション全体の検索と置換は、既存の結果処理コードで名前の変更を処理します。

CI/CDパイプラインでIronBarcodeのライセンスを設定するには?

IRONBARCODE_LICENSE_KEYをパイプラインシークレットとして保存し、アプリケーションの起動コードにIronBarCode.License.LicenseKeyを割り当てます。1つのシークレットで、開発環境、テスト環境、ステージング環境、本番環境を含むすべての環境をカバーできます。

IronBarcodeはカスタムスタイルのQRコード生成に対応していますか?

はい。QRCodeWriter.CreateQrCode()は、ChangeBarCodeColor()によるカスタムカラー、AddBrandLogo()によるロゴ埋め込み、設定可能なエラー訂正レベル、PNG、JPG、PDF、ストリームなどの複数の出力形式をサポートしています。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

アイアンサポートチーム

私たちは週5日、24時間オンラインで対応しています。
チャット
メール
電話してね