Wie man Barcodes aus System Drawing-Objekten liest
Migrating from Cloudmersive Barcode API to IronBarcode
Dies ist die einfachste Migration in der Geschichte von .NET -Barcodes. Entfernen Sie den HTTP-Client. Fügen Sie ein NuGet-Paket hinzu. Die API-Schlüsselverwaltung wird gelöscht. Der Rest ist eine Suche-und-Ersetzungs-Maßnahme.
Das .NET SDK von Cloudmersive ist ein generierter REST API-Client – ein dünner Wrapper um HttpClient Aufrufe. Jeder Cloudmersive-spezifische Code in Ihrer Anwendung ist entweder eine Konfiguration für diesen Client, ein Aufruf über diesen Client oder eine Fehlerbehandlung für den Fall, dass Netzwerkanfragen fehlschlagen. Für IronBarcode wird keine dieser Infrastrukturen benötigt, da Barcodes lokal und ohne Netzwerkabhängigkeit verarbeitet werden.
Schnellstart: Drei Schritte
Schritt 1: Pakete tauschen
dotnet remove package Cloudmersive.APIClient.NET.Barcode
dotnet add package BarCode
dotnet remove package Cloudmersive.APIClient.NET.Barcode
dotnet add package BarCode
Schritt 2: Namensräume ersetzen
// 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
Schritt 3: API-Schlüssel-Einrichtung durch Lizenzschlüssel ersetzen
// 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"
In einer ASP.NET Core-Anwendung wird der Lizenzschlüssel in Program.cs vor builder.Build() platziert:
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
Kosten: Ihre bisherigen Ausgaben vs. Ihre zukünftigen Ausgaben
Vor der Migration ist es ratsam, die tatsächlichen Kosten der Cloudmersive-Integration zu berechnen. Die Rechnung ist einfach:
| Ihr tägliches Volumen | Monatliche Anfragen | Cloudmersive Stufe | IronBarcode (einmalig) |
|---|---|---|---|
| 100/Tag | ~3.000 | Basis $19,99/Monat | $749 |
| 1.000/Tag | ~30.000 | Business Premier $99,99/Monat | $749 |
| 5.000/Tag | ~150.000 | Mittleres Unternehmen $499,99/Monat | $749 |
| 10.000/Tag | ~300.000 | Enterprise (kundenspezifisch) | $749 |
| 25.000/Tag | ~750.000 | Enterprise (kundenspezifisch) | 1.499 $ (Plus, 3 Entwickler) |
Wenn Sie mehr als ~63$/Monat für Cloudmersive bezahlen, amortisiert sich die Lite-Lizenz von IronBarcode innerhalb des ersten Jahres. Nach dem Break-even ist IronBarcode eine unbefristete Lizenz ohne Erneuerung und ohne Gebühren pro Anfrage.
Beispiele für die Code-Migration
QR-Code-Generierung
Der am häufigsten verwendete Cloudmersive-Generierungsaufruf ist direkt IronBarcode zugeordnet:
Vorher (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)
Nach (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")
Code-128-Generierung
Vorher (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)
Nach (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()
BarCode lesen
Vorher (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
Nach (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}")
Asynchrones Barcode-Lesen
Wenn Ihre Cloudmersive-Integration die asynchrone API verwendet:
Vorher (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
Nach (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
Barcodes aus PDFs lesen
Cloudmersive bietet keine native PDF-Unterstützung. Falls Ihr bestehender Code Bilder aus PDFs extrahiert, bevor er sie scannt, ersetzen Sie diese gesamte Pipeline durch einen einzigen IronBarcode -Aufruf:
Vorher (Cloudmersive – erfordert separate PDF-Extraktion):
// 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
Nach (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
Erkennung mehrerer Barcodes
Wenn Sie Code besitzen, der Dokumente mit mehreren Barcodes scannt:
Vorher (Cloudmersive – mehrere Anrufe erforderlich):
// 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
Nach (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()
Entfernung nicht mehr benötigter Infrastruktur
Dies ist der Teil der Migration, bei dem man mehr Code löscht als neu schreibt.
HTTP-Ausnahmebehandlung entfernen
Bei Cloudmersive-Operationen kann es zu Netzwerkfehlern, HTTP 4xx/5xx-Antworten und Timeout-Ausnahmen kommen. Dies erzeugt typischerweise eine try/catch-Infrastruktur, die IronBarcode nicht benötigt:
// 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
IronBarcode löst keine Netzwerk-Ausnahmen aus. Es wirft BarcodeException, wenn ein Barcode aus der Eingabe nicht dekodiert werden kann, was ein Inhaltsproblem und kein Infrastrukturproblem ist. Die vereinfachte Fehlerbehandlung:
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
Wiederholungslogik entfernen
Falls Ihre Cloudmersive-Integration Wiederholungsrichtlinien enthält – Polly, benutzerdefinierte Wiederholungsschleifen oder exponentielles Backoff –, entfernen Sie diese vollständig:
// 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")
Ratenbegrenzungs-Tracking entfernen
Wenn Ihr Code die Anzahl der API-Aufrufe erfasst, um das monatliche Kontingent von Cloudmersive einzuhalten:
// 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")
Netzwerk-Timeout-Konfiguration entfernen
Cloudmersive-Clients beinhalten häufig eine Timeout-Konfiguration. Entfernen Sie es:
// 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
API-Schlüsselrotation entfernen
Wenn Ihre Anwendung API-Schlüssel nach einem Zeitplan rotiert oder sie in der Geheimnisverwaltung speichert:
// 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"
Gängige Probleme bei der Migration
Cloudmersive gab byte[] für die Generierung zurück
Die Generierungsmethoden von Cloudmersive geben byte[] direkt zurück. IronBarcode gibt ein GeneratedBarcode Objekt zurück, das Ihnen mehr Optionen bietet:
// 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()
Cloudmersive Reading lieferte ein JSON-Antwortmodell zurück.
Das Scan-Ergebnis von Cloudmersive ist ein Response-Modell mit Eigenschaften wie Successful, RawText und BarcodeType. IronBarcode gibt typisierte Ergebnisobjekte zurück:
// 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
Mehrere Cloudmersive API-Instanztypen
Cloudmersive trennt die Generierung und das Scannen in GenerateBarcodeApi und BarcodeScanApi Instanzen. IronBarcode verwendet statische Klassen – es werden keine Instanzen benötigt:
// 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
Migrations-Checkliste
Führen Sie diese Suchvorgänge in Ihrer Codebasis vor und nach der Migration durch, um sicherzustellen, dass Sie jede Cloudmersive-Referenz erfasst haben:
# 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" .
Nach der Migration sollten alle Suchvorgänge keine Ergebnisse mehr liefern. Überprüfen Sie anschließend, ob IronBarcode korrekt referenziert wird:
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" .
Konfigurationscheckliste
- Entfernen Sie
Cloudmersive.APIClient.NET.Barcodeaus allen.csprojDateien - Entfernen Sie den Cloudmersive API-Schlüssel aus
appsettings.json, Umgebungsvariablen und Geheimnisspeichern - Fügen Sie das IronBarcode NuGet -Paket hinzu
- Fügen Sie
IronBarCode.License.LicenseKeyInitialisierung beim Anwendungsstart hinzu - Entfernen von Wiederholungsrichtlinien und Schutzschaltern für Cloudmersive-Anrufe
- Ratenbegrenzungs-Tracking-Code entfernen
- Netzwerk-Timeout-Konfiguration entfernen
Checkliste für Tests
Nach Abschluss der Migration:
- Überprüfen Sie, ob die QR-Code-Generierung gültige, scannbare Ergebnisse liefert.
- Überprüfung der Code128- und anderer linearer Barcode-Generierungen
- Überprüfung der Barcode-Lesbarkeit gängiger Bildformate (PNG, JPEG, BMP)
- Testen Sie das Lesen von PDFs, wenn Sie PDF-Dokumente verarbeiten.
- Testen Sie gegebenenfalls die Erkennung mehrerer Barcodes.
- Sicherstellen, dass keine Cloudmersive-API-Aufrufe im Netzwerkverkehr auftreten
- Prüfen Sie, ob die Anwendung auch ohne Internetverbindung korrekt funktioniert.
Was Sie nach der Migration gewinnen
Neben den Kosteneinsparungen beseitigt die Migration eine ganze Kategorie von betrieblichen Problemen:
Die Barcodeverarbeitung ist nicht mehr netzwerkabhängig. Ihre Dokumentenverarbeitungspipeline läuft unabhängig von der Verfügbarkeit von Cloudmersive, der Qualität Ihrer Internetverbindung oder Spitzenwerten der Netzwerklatenz.
Keine Quotenverwaltung mehr. Dokumentmengenspitzen zum Monatsende führen nicht mehr zu unerwarteten Überschreitungen oder Verarbeitungsfehlern.
Es verlassen keine Daten mehr Ihr Netzwerk. Barcode-Bilder, die sensible Kunden-, Finanz- oder Gesundheitsinformationen enthalten, verbleiben auf Ihrer Infrastruktur.
Einfacherer Code. Die für Cloudmersive-Produktionsintegrationen erforderliche Infrastruktur für Wiederholungsversuche, Timeout-Behandlung und HTTP-Ausnahmemanagement entfällt. Anstelle dessen erfolgt ein direkter Methodenaufruf.
Die Migration ist mechanisch. Die Vorteile liegen in der Struktur – die Abhängigkeit eines Arbeitsablaufs von einem externen Netzwerkdienst wird beseitigt, da dieser keinen solchen benötigt.
Häufig gestellte Fragen
Warum sollte ich von Cloudmersive Barcode API zu IronBarcode migrieren?
Zu den häufigsten Gründen gehören die Vereinfachung der Lizenzierung (Beseitigung der Komplexität von SDK und Laufzeitschlüsseln), die Beseitigung von Durchsatzbeschränkungen, die Verbesserung der nativen PDF-Unterstützung, die Verbesserung der Docker/CI/CD-Bereitstellung und die Verringerung von API-Boilerplate im Produktionscode.
Wie kann ich Cloudmersive API-Aufrufe durch IronBarcode ersetzen?
Ersetzen Sie Instanzerstellung und Lizenzierung durch IronBarCode.License.LicenseKey = "key". Ersetzen Sie die Leseaufrufe durch BarcodeReader.Read(path) und die Schreibaufrufe durch BarcodeWriter.CreateBarcode(data, encoding). Statische Methoden erfordern keine Instanzverwaltung.
Wie viel Code ändert sich bei der Migration von Cloudmersive Barcode API zu IronBarcode?
Die meisten Migrationen führen zu weniger Codezeilen. Lizenzierungs-Boilerplate, Instanzkonstruktoren und explizite Formatkonfiguration werden entfernt. Zentrale Lese-/Schreibvorgänge werden auf kürzere IronBarcode-Äquivalente mit saubereren Ergebnisobjekten abgebildet.
Muss ich während der Migration sowohl Cloudmersive Barcode API als auch IronBarcode installiert lassen?
Nein. Die meisten Migrationen sind direkte Ersetzungen und keine Paralleloperationen. Migrieren Sie eine Serviceklasse nach der anderen, ersetzen Sie die NuGet-Referenz und aktualisieren Sie die Instanzierungs- und API-Aufrufmuster, bevor Sie zur nächsten Klasse übergehen.
Wie lautet der NuGet-Paketname für IronBarcode?
Das Paket ist 'IronBarCode' (mit großem B und C). Installieren Sie es mit 'Install-Package IronBarCode' oder 'dotnet add package IronBarCode'. Die using-Anweisung im Code lautet 'using IronBarCode;'.
Wie vereinfacht IronBarcode die Docker-Bereitstellung im Vergleich zur Cloudmersive BarCode API?
IronBarcode ist ein NuGet-Paket, für das keine externen SDK-Dateien oder Lizenzkonfigurationen erforderlich sind. In Docker setzen Sie die Umgebungsvariable IRONBARCODE_LICENSE_KEY und das Paket übernimmt die Lizenzvalidierung beim Start.
Erkennt IronBarcode alle Barcode-Formate automatisch nach der Migration von Cloudmersive?
Ja, IronBarcode erkennt automatisch die Symbologie aller unterstützten Formate. Eine explizite Aufzählung von BarcodeTypes ist nicht erforderlich. Wenn das Format bereits bekannt ist und die Leistung eine Rolle spielt, ermöglicht BarcodeReaderOptions die Einschränkung des Suchraums als eine Optimierung.
Kann IronBarcode Barcodes aus PDFs ohne eine separate Bibliothek lesen?
Ja, BarcodeReader.Read("document.pdf") verarbeitet PDF-Dateien nativ. Die Ergebnisse enthalten PageNumber, Format, Value und Confidence für jeden gefundenen Barcode. Es ist kein externer PDF-Rendering-Schritt erforderlich.
Wie handhabt IronBarcode die parallele Verarbeitung von Barcodes?
Die statischen Methoden von IronBarcode sind zustandslos und thread-sicher. Verwenden Sie Parallel.ForEach direkt über Dateilisten ohne Instanzmanagement pro Thread. BarcodeReaderOptions.MaxParallelThreads steuert das interne Thread-Budget.
Welche Ergebniseigenschaften ändern sich bei der Migration von Cloudmersive Barcode API zu IronBarcode?
Übliche Umbenennungen: BarcodeValue wird zu Value, BarcodeType wird zu Format. IronBarcode-Ergebnisse fügen auch Confidence und PageNumber hinzu. Eine lösungsweite Such- und Ersetzungsfunktion übernimmt die Umbenennungen im bestehenden Ergebnisverarbeitungscode.
Wie kann ich die IronBarcode-Lizenzierung in einer CI/CD-Pipeline einrichten?
Speichern Sie IRONBARCODE_LICENSE_KEY als Pipeline-Geheimnis und weisen Sie IronBarCode.License.LicenseKey im Startup-Code der Anwendung zu. Ein Geheimnis deckt alle Umgebungen ab, einschließlich Entwicklung, Test, Staging und Produktion.
Unterstützt IronBarcode die Generierung von QR-Codes mit benutzerdefiniertem Styling?
Ja. QRCodeWriter.CreateQrCode() unterstützt benutzerdefinierte Farben über ChangeBarCodeColor(), das Einbetten von Logos über AddBrandLogo(), konfigurierbare Fehlerkorrekturstufen und mehrere Ausgabeformate einschließlich PNG, JPG, PDF und Stream.

