Wie man mehrere Barcodes gleichzeitig in C# liest
Migrating from DevExpress BarCodeto IronBarcode
Wenn Sie DevExpress wegen seiner Grid-, Chart-, Scheduler- oder Pivot-Steuerelemente verwenden, behalten Sie diese bei. Diese Migration bezieht sich speziell auf den Ersatz von BarCodeControl durch eine Bibliothek, die auch Barcodes lesen, kopflos laufen und außerhalb eines UI-Kontexts bereitstellen kann. Die DevExpress UI-Steuerelemente, auf die Sie sich für Ihre WinForms- oder Blazor -Anwendung verlassen, werden von dieser Migration nicht betroffen sein. Es ändert sich lediglich der barcodespezifische Code.
Das typische Szenario, das diese Migration auslöst, ist eines von drei Dingen: Es tritt eine Leseanforderung auf, die DevExpress nicht erfüllen kann; Ein neuer Dienst benötigt Barcode-Generierung in ASP.NET Core oder einer Cloud-Funktion, in der keine WinForms-Assemblys vorhanden sind; oder wenn die Suite erneuert wird und die Kosten-pro-Funktion-Rechnung für die Verwendung eines kompletten UI-Toolkits allein für die Barcode-Ausgabe nicht mehr sinnvoll ist.
Schritt 1: IronBarcode installieren
dotnet add package BarCode
Wenn Sie andere DevExpress-Steuerelemente im selben Projekt verwenden, lassen Sie die DevExpress NuGet Pakete an Ort und Stelle. Es ändert sich lediglich der Barcode-bezogene Code in Ihren Quelldateien. Wenn die Barcode-Generierung der einzige Grund für die Verwendung von DevExpress in einem bestimmten Projekt war und Sie dort keine anderen DX-Steuerelemente verwenden, können Sie die DevExpress-Pakete nach der Migration aus diesem Projekt entfernen:
# Only remove DevExpress packages if no other DX controls are used in this project
dotnet remove package DevExpress.Win.Navigation
# Only remove DevExpress packages if no other DX controls are used in this project
dotnet remove package DevExpress.Win.Navigation
Schritt 2: Lizenzinitialisierung hinzufügen
Fügen Sie die IronBarcode-Lizenzaktivierung einmal beim Start der Anwendung hinzu — in Program.cs, App.xaml.cs oder Ihrem Host-Builder:
// In Program.cs (ASP.NET Core) or application entry point
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// In Program.cs (ASP.NET Core) or application entry point
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
Imports IronBarCode
' In Program.vb (ASP.NET Core) or application entry point
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
Kein Netzwerkanruf. Kein Fehlercode zum Überprüfen. Lokale Validierung.
Schritt 3: Barcodespezifischen Code ersetzen
Durchsuchen Sie Ihren Quellcode nach DevExpress-Barcodetypen. Alles andere bleibt unverändert:
# Find barcode-related DevExpress usage — ignore grid, chart, and other DX components
grep -r "BarCodeControl\|Code128Generator\|QRCodeGenerator\|DataMatrixGenerator\|PDF417Generator\|AztecCodeGenerator\|DevExpress.XtraPrinting.BarCode" --include="*.cs" .
grep -r "barCode\.Module\|DrawToBitmap\|BarCode\.Symbology" --include="*.cs" .
# Find barcode-related DevExpress usage — ignore grid, chart, and other DX components
grep -r "BarCodeControl\|Code128Generator\|QRCodeGenerator\|DataMatrixGenerator\|PDF417Generator\|AztecCodeGenerator\|DevExpress.XtraPrinting.BarCode" --include="*.cs" .
grep -r "barCode\.Module\|DrawToBitmap\|BarCode\.Symbology" --include="*.cs" .
Die Ergebnisse dieser Suche sind genau das, was Sie ersetzen werden. Sonst nichts.
Beispiele für die Code-Migration
Code 128 Erzeugung
Dies ist die häufigste Migrationsart. Ein BarCodeControl mit einer Code128Generator-Symbologie wird zu einem einzelnen BarcodeWriter.CreateBarcode-Aufruf.
Vorher — DevExpress WinForms-Steuerelement:
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
using System.Drawing;
using System.Drawing.Imaging;
public void GenerateCode128(string data, string outputPath)
{
var barCode = new BarCodeControl();
var symbology = new Code128Generator();
symbology.CharacterSet = Code128CharacterSet.CharsetAuto;
barCode.Symbology = symbology;
barCode.Text = data;
barCode.Module = 0.02f;
barCode.ShowText = true;
barCode.Width = 400;
barCode.Height = 100;
var bitmap = new Bitmap(barCode.Width, barCode.Height);
barCode.DrawToBitmap(bitmap, new Rectangle(0, 0, barCode.Width, barCode.Height));
bitmap.Save(outputPath, ImageFormat.Png);
bitmap.Dispose();
}
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
using System.Drawing;
using System.Drawing.Imaging;
public void GenerateCode128(string data, string outputPath)
{
var barCode = new BarCodeControl();
var symbology = new Code128Generator();
symbology.CharacterSet = Code128CharacterSet.CharsetAuto;
barCode.Symbology = symbology;
barCode.Text = data;
barCode.Module = 0.02f;
barCode.ShowText = true;
barCode.Width = 400;
barCode.Height = 100;
var bitmap = new Bitmap(barCode.Width, barCode.Height);
barCode.DrawToBitmap(bitmap, new Rectangle(0, 0, barCode.Width, barCode.Height));
bitmap.Save(outputPath, ImageFormat.Png);
bitmap.Dispose();
}
Imports DevExpress.XtraEditors
Imports DevExpress.XtraPrinting.BarCode
Imports System.Drawing
Imports System.Drawing.Imaging
Public Sub GenerateCode128(data As String, outputPath As String)
Dim barCode As New BarCodeControl()
Dim symbology As New Code128Generator()
symbology.CharacterSet = Code128CharacterSet.CharsetAuto
barCode.Symbology = symbology
barCode.Text = data
barCode.Module = 0.02F
barCode.ShowText = True
barCode.Width = 400
barCode.Height = 100
Dim bitmap As New Bitmap(barCode.Width, barCode.Height)
barCode.DrawToBitmap(bitmap, New Rectangle(0, 0, barCode.Width, barCode.Height))
bitmap.Save(outputPath, ImageFormat.Png)
bitmap.Dispose()
End Sub
Nach — IronBarcode:
// NuGet: dotnet add package BarCode
using IronBarCode;
public void GenerateCode128(string data, string outputPath)
{
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.SaveAsPng(outputPath);
}
// NuGet: dotnet add package BarCode
using IronBarCode;
public void GenerateCode128(string data, string outputPath)
{
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.SaveAsPng(outputPath);
}
Imports IronBarCode
Public Sub GenerateCode128(data As String, outputPath As String)
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128) _
.ResizeTo(400, 100) _
.SaveAsPng(outputPath)
End Sub
Das barCode.Module = 0.02f-Dokumenteinheitensizing ist weg. .ResizeTo(400, 100) nimmt direkt Pixel. Die manuelle Bitmap-Allokation und der DrawToBitmap-Aufruf werden durch .SaveAsPng() ersetzt, die das Sizing automatisch verwaltet.
QR-Code-Generierung
Vorher — DevExpress QR mit Fehlerkorrektur:
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
using System.Drawing;
using System.Drawing.Imaging;
public void GenerateQrCode(string url, string outputPath)
{
var barCode = new BarCodeControl();
var symbology = new QRCodeGenerator();
symbology.ErrorCorrectionLevel = QRCodeErrorCorrectionLevel.H;
symbology.CompactionMode = QRCodeCompactionMode.AlphaNumeric;
barCode.Symbology = symbology;
barCode.Text = url;
barCode.Width = 500;
barCode.Height = 500;
var bitmap = new Bitmap(barCode.Width, barCode.Height);
barCode.DrawToBitmap(bitmap, new Rectangle(0, 0, barCode.Width, barCode.Height));
bitmap.Save(outputPath, ImageFormat.Png);
bitmap.Dispose();
}
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
using System.Drawing;
using System.Drawing.Imaging;
public void GenerateQrCode(string url, string outputPath)
{
var barCode = new BarCodeControl();
var symbology = new QRCodeGenerator();
symbology.ErrorCorrectionLevel = QRCodeErrorCorrectionLevel.H;
symbology.CompactionMode = QRCodeCompactionMode.AlphaNumeric;
barCode.Symbology = symbology;
barCode.Text = url;
barCode.Width = 500;
barCode.Height = 500;
var bitmap = new Bitmap(barCode.Width, barCode.Height);
barCode.DrawToBitmap(bitmap, new Rectangle(0, 0, barCode.Width, barCode.Height));
bitmap.Save(outputPath, ImageFormat.Png);
bitmap.Dispose();
}
Imports DevExpress.XtraEditors
Imports DevExpress.XtraPrinting.BarCode
Imports System.Drawing
Imports System.Drawing.Imaging
Public Sub GenerateQrCode(url As String, outputPath As String)
Dim barCode As New BarCodeControl()
Dim symbology As New QRCodeGenerator()
symbology.ErrorCorrectionLevel = QRCodeErrorCorrectionLevel.H
symbology.CompactionMode = QRCodeCompactionMode.AlphaNumeric
barCode.Symbology = symbology
barCode.Text = url
barCode.Width = 500
barCode.Height = 500
Dim bitmap As New Bitmap(barCode.Width, barCode.Height)
barCode.DrawToBitmap(bitmap, New Rectangle(0, 0, barCode.Width, barCode.Height))
bitmap.Save(outputPath, ImageFormat.Png)
bitmap.Dispose()
End Sub
Nach — IronBarcode:
using IronBarCode;
public void GenerateQrCode(string url, string outputPath)
{
QRCodeWriter.CreateQrCode(url, 500, QRCodeWriter.QrErrorCorrectionLevel.Highest)
.SaveAsPng(outputPath);
}
using IronBarCode;
public void GenerateQrCode(string url, string outputPath)
{
QRCodeWriter.CreateQrCode(url, 500, QRCodeWriter.QrErrorCorrectionLevel.Highest)
.SaveAsPng(outputPath);
}
Imports IronBarCode
Public Sub GenerateQrCode(url As String, outputPath As String)
QRCodeWriter.CreateQrCode(url, 500, QRCodeWriter.QrErrorCorrectionLevel.Highest) _
.SaveAsPng(outputPath)
End Sub
QRCodeErrorCorrectionLevel.H mappt auf QRCodeWriter.QrErrorCorrectionLevel.Highest. Die CompactionMode.AlphaNumeric-Einstellung wird von IronBarcode basierend auf dem Inhalt automatisch gehandhabt.
QR-Code mit Markenlogo (neue Funktion – mit DevExpress nicht möglich):
using IronBarCode;
public void GenerateBrandedQrCode(string url, string logoPath, string outputPath)
{
QRCodeWriter.CreateQrCode(url, 500, QRCodeWriter.QrErrorCorrectionLevel.Highest)
.AddBrandLogo(logoPath)
.SaveAsPng(outputPath);
}
using IronBarCode;
public void GenerateBrandedQrCode(string url, string logoPath, string outputPath)
{
QRCodeWriter.CreateQrCode(url, 500, QRCodeWriter.QrErrorCorrectionLevel.Highest)
.AddBrandLogo(logoPath)
.SaveAsPng(outputPath);
}
Imports IronBarCode
Public Sub GenerateBrandedQrCode(url As String, logoPath As String, outputPath As String)
QRCodeWriter.CreateQrCode(url, 500, QRCodeWriter.QrErrorCorrectionLevel.Highest) _
.AddBrandLogo(logoPath) _
.SaveAsPng(outputPath)
End Sub
Datenmatrixgenerierung
Vorher — DevExpress:
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
var barCode = new BarCodeControl();
var symbology = new DataMatrixGenerator();
symbology.MatrixSize = DataMatrixSize.Matrix26x26;
barCode.Symbology = symbology;
barCode.Text = "PART-7734-X";
// ... DrawToBitmap pattern
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
var barCode = new BarCodeControl();
var symbology = new DataMatrixGenerator();
symbology.MatrixSize = DataMatrixSize.Matrix26x26;
barCode.Symbology = symbology;
barCode.Text = "PART-7734-X";
// ... DrawToBitmap pattern
Imports DevExpress.XtraEditors
Imports DevExpress.XtraPrinting.BarCode
Dim barCode As New BarCodeControl()
Dim symbology As New DataMatrixGenerator()
symbology.MatrixSize = DataMatrixSize.Matrix26x26
barCode.Symbology = symbology
barCode.Text = "PART-7734-X"
' ... DrawToBitmap pattern
Nach — IronBarcode:
using IronBarCode;
BarcodeWriter.CreateBarcode("PART-7734-X", BarcodeEncoding.DataMatrix)
.ResizeTo(260, 260)
.SaveAsPng("datamatrix.png");
using IronBarCode;
BarcodeWriter.CreateBarcode("PART-7734-X", BarcodeEncoding.DataMatrix)
.ResizeTo(260, 260)
.SaveAsPng("datamatrix.png");
Imports IronBarCode
BarcodeWriter.CreateBarcode("PART-7734-X", BarcodeEncoding.DataMatrix) _
.ResizeTo(260, 260) _
.SaveAsPng("datamatrix.png")
PDF417-Generierung
Vorher — DevExpress:
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
var barCode = new BarCodeControl();
barCode.Symbology = new PDF417Generator();
barCode.Text = "SHIPMENT-DATA-2026";
// ... DrawToBitmap pattern
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
var barCode = new BarCodeControl();
barCode.Symbology = new PDF417Generator();
barCode.Text = "SHIPMENT-DATA-2026";
// ... DrawToBitmap pattern
Imports DevExpress.XtraEditors
Imports DevExpress.XtraPrinting.BarCode
Dim barCode As New BarCodeControl()
barCode.Symbology = New PDF417Generator()
barCode.Text = "SHIPMENT-DATA-2026"
' ... DrawToBitmap pattern
Nach — IronBarcode:
using IronBarCode;
BarcodeWriter.CreateBarcode("SHIPMENT-DATA-2026", BarcodeEncoding.PDF417)
.ResizeTo(400, 150)
.SaveAsPng("pdf417.png");
using IronBarCode;
BarcodeWriter.CreateBarcode("SHIPMENT-DATA-2026", BarcodeEncoding.PDF417)
.ResizeTo(400, 150)
.SaveAsPng("pdf417.png");
Imports IronBarCode
BarcodeWriter.CreateBarcode("SHIPMENT-DATA-2026", BarcodeEncoding.PDF417) _
.ResizeTo(400, 150) _
.SaveAsPng("pdf417.png")
Hinzufügen der Lesefähigkeit (neue Funktion)
DevExpress bietet keine Lese-API an. Wenn eine Leseanforderung gestellt wird, macht sich IronBarcode sofort bezahlt:
using IronBarCode;
// Read from an image file
var results = BarcodeReader.Read("uploaded-label.png");
foreach (var result in results)
{
Console.WriteLine($"Found {result.Format}: {result.Value}");
}
// Read with options for better accuracy on difficult images
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
MaxParallelThreads = 4
};
var detailedResults = BarcodeReader.Read("multi-barcode-sheet.png", options);
using IronBarCode;
// Read from an image file
var results = BarcodeReader.Read("uploaded-label.png");
foreach (var result in results)
{
Console.WriteLine($"Found {result.Format}: {result.Value}");
}
// Read with options for better accuracy on difficult images
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
MaxParallelThreads = 4
};
var detailedResults = BarcodeReader.Read("multi-barcode-sheet.png", options);
Imports IronBarCode
' Read from an image file
Dim results = BarcodeReader.Read("uploaded-label.png")
For Each result In results
Console.WriteLine($"Found {result.Format}: {result.Value}")
Next
' Read with options for better accuracy on difficult images
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.MaxParallelThreads = 4
}
Dim detailedResults = BarcodeReader.Read("multi-barcode-sheet.png", options)
ASP.NET Core Barcode-Endpunkt
Dies war mit BarCodeControl ohne WinForms-Workarounds nicht erreichbar. IronBarcode unterstützt dies nativ:
using IronBarCode;
// In Program.cs or a controller
app.MapGet("/label/{sku}", (string sku) =>
{
var pngBytes = BarcodeWriter.CreateBarcode(sku, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.ToPngBinaryData();
return Results.File(pngBytes, "image/png", $"{sku}.png");
});
app.MapGet("/qr/{data}", (string data) =>
{
var pngBytes = QRCodeWriter.CreateQrCode(data, 300, QRCodeWriter.QrErrorCorrectionLevel.Highest)
.ToPngBinaryData();
return Results.File(pngBytes, "image/png");
});
using IronBarCode;
// In Program.cs or a controller
app.MapGet("/label/{sku}", (string sku) =>
{
var pngBytes = BarcodeWriter.CreateBarcode(sku, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.ToPngBinaryData();
return Results.File(pngBytes, "image/png", $"{sku}.png");
});
app.MapGet("/qr/{data}", (string data) =>
{
var pngBytes = QRCodeWriter.CreateQrCode(data, 300, QRCodeWriter.QrErrorCorrectionLevel.Highest)
.ToPngBinaryData();
return Results.File(pngBytes, "image/png");
});
Imports IronBarCode
' In Program.vb or a controller
app.MapGet("/label/{sku}", Function(sku As String)
Dim pngBytes = BarcodeWriter.CreateBarcode(sku, BarcodeEncoding.Code128) _
.ResizeTo(400, 100) _
.ToPngBinaryData()
Return Results.File(pngBytes, "image/png", $"{sku}.png")
End Function)
app.MapGet("/qr/{data}", Function(data As String)
Dim pngBytes = QRCodeWriter.CreateQrCode(data, 300, QRCodeWriter.QrErrorCorrectionLevel.Highest) _
.ToPngBinaryData()
Return Results.File(pngBytes, "image/png")
End Function)
Barcodes aus PDFs lesen
IronBarcode kann PDF-Dateien nativ lesen. Kein PdfiumViewer, keine Rendering-Schleife, keine zusätzlichen Pakete:
using IronBarCode;
// Read all barcodes from all pages of a PDF
var results = BarcodeReader.Read("shipping-manifest.pdf");
foreach (var result in results)
{
Console.WriteLine($"Barcode: {result.Value} | Format: {result.Format}");
}
using IronBarCode;
// Read all barcodes from all pages of a PDF
var results = BarcodeReader.Read("shipping-manifest.pdf");
foreach (var result in results)
{
Console.WriteLine($"Barcode: {result.Value} | Format: {result.Format}");
}
Imports IronBarCode
' Read all barcodes from all pages of a PDF
Dim results = BarcodeReader.Read("shipping-manifest.pdf")
For Each result In results
Console.WriteLine($"Barcode: {result.Value} | Format: {result.Format}")
Next
Gängige Probleme bei der Migration
Das barCode.Module verwendet Dokumenteinheiten, nicht Pixel.
barCode.Module steuert die Breite der schmalsten Leiste in Dokumenteneinheiten (abhängig vom Rendering DPI-Kontext). Dies ist keine Pixelzählung. Beim Migrieren versuchen Sie nicht, den Modulwert in Pixel umzuwandeln – entscheiden Sie stattdessen, welche Pixelabmessungen Sie möchten, und verwenden Sie .ResizeTo(width, height) direkt.
// Before: barCode.Module = 0.02f — document units, indirect sizing
// After:
.ResizeTo(400, 100) // explicit pixel dimensions
// Before: barCode.Module = 0.02f — document units, indirect sizing
// After:
.ResizeTo(400, 100) // explicit pixel dimensions
' Before: barCode.Module = 0.02F — document units, indirect sizing
' After:
.ResizeTo(400, 100) ' explicit pixel dimensions
DrawToBitmap erfordert eine vorab zugewiesene Bitmap.
Das alte Muster allokierte einen Bitmap in einer bestimmten Größe, dann wurde DrawToBitmap aufgerufen, um darin zu rendern. IronBarcodes .SaveAsPng() behandelt all dies intern. Sie reservieren nichts im Voraus.
// Before: must know size upfront, allocate, draw, save, dispose
barCode.Width = 400;
barCode.Height = 100;
var bitmap = new Bitmap(barCode.Width, barCode.Height);
barCode.DrawToBitmap(bitmap, new Rectangle(0, 0, barCode.Width, barCode.Height));
bitmap.Save(path, ImageFormat.Png);
bitmap.Dispose();
// After: size specified once, everything else handled
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.SaveAsPng(path);
// Before: must know size upfront, allocate, draw, save, dispose
barCode.Width = 400;
barCode.Height = 100;
var bitmap = new Bitmap(barCode.Width, barCode.Height);
barCode.DrawToBitmap(bitmap, new Rectangle(0, 0, barCode.Width, barCode.Height));
bitmap.Save(path, ImageFormat.Png);
bitmap.Dispose();
// After: size specified once, everything else handled
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.SaveAsPng(path);
' Before: must know size upfront, allocate, draw, save, dispose
barCode.Width = 400
barCode.Height = 100
Dim bitmap As New Bitmap(barCode.Width, barCode.Height)
barCode.DrawToBitmap(bitmap, New Rectangle(0, 0, barCode.Width, barCode.Height))
bitmap.Save(path, ImageFormat.Png)
bitmap.Dispose()
' After: size specified once, everything else handled
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128) _
.ResizeTo(400, 100) _
.SaveAsPng(path)
WinForms-Datenbindung
Wenn BarCodeControl in einem WinForms-Designer an eine Datenquelle gebunden war, besteht das IronBarcode-Äquivalent darin, den Wert explizit aus Ihrem Modell zu lesen und an BarcodeWriter.CreateBarcode zu übergeben. IronBarcode nimmt nicht an der WinForms-Datenbindung teil – es handelt sich um eine programmatische API, nicht um ein UI-Steuerelement. Wenn Sie den generierten Barcode auf einem Formular anzeigen müssen, generieren Sie die Bild-Bytes und setzen Sie sie auf einem PictureBox:
using IronBarCode;
// Generate and display in a WinForms PictureBox
private void UpdateBarcodeDisplay(string value)
{
var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.ToPngBinaryData();
using var ms = new System.IO.MemoryStream(bytes);
pictureBox1.Image = System.Drawing.Image.FromStream(ms);
}
using IronBarCode;
// Generate and display in a WinForms PictureBox
private void UpdateBarcodeDisplay(string value)
{
var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.ToPngBinaryData();
using var ms = new System.IO.MemoryStream(bytes);
pictureBox1.Image = System.Drawing.Image.FromStream(ms);
}
Imports IronBarCode
Imports System.IO
' Generate and display in a WinForms PictureBox
Private Sub UpdateBarcodeDisplay(value As String)
Dim bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128) _
.ResizeTo(400, 100) _
.ToPngBinaryData()
Using ms As New MemoryStream(bytes)
pictureBox1.Image = System.Drawing.Image.FromStream(ms)
End Using
End Sub
Namensraumersetzung
Alte Importe zu entfernen:
// Remove these
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
// Remove these
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
Neuer Import hinzufügen:
// Add this
using IronBarCode;
// Add this
using IronBarCode;
Imports IronBarCode
API-Mapping-Referenz
| DevExpress BarCode | IronBarcode Äquivalent |
|---|---|
new BarCodeControl() |
Statisch – keine Instanz |
new Code128Generator() + barCode.Symbology = symbology |
BarcodeEncoding.Code128-Parameter |
new QRCodeGenerator() + QRCodeErrorCorrectionLevel.H |
QRCodeWriter.CreateQrCode(data, size, QRCodeWriter.QrErrorCorrectionLevel.Highest) |
new DataMatrixGenerator() + DataMatrixSize.Matrix26x26 |
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.DataMatrix) |
new PDF417Generator() |
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.PDF417) |
new AztecCodeGenerator() |
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Aztec) |
barCode.Text = value |
Erstes Argument zu CreateBarcode oder CreateQrCode |
barCode.Module = 0.02f |
.ResizeTo(width, height) in Pixel |
barCode.ShowText = true |
.AddBarcodeText() |
DrawToBitmap(bitmap, rect) |
.SaveAsPng(path) |
new Bitmap(w, h) + manuelle Entsorgung |
Nicht erforderlich |
Bitmap → MemoryStream → HTTP |
.ToPngBinaryData() |
| Keine Lese-API | BarcodeReader.Read(path) |
using DevExpress.XtraEditors + using DevExpress.XtraPrinting.BarCode |
using IronBarCode |
Migrations-Checkliste
Verwenden Sie dieses grep-Muster, um alle Dateien zu finden, die aktualisiert werden müssen:
grep -r "BarCodeControl\|Code128Generator\|QRCodeGenerator\|DataMatrixGenerator\|PDF417Generator\|AztecCodeGenerator" --include="*.cs" .
grep -r "barCode\.Module\|barCode\.Symbology\|DrawToBitmap\|DevExpress\.XtraPrinting\.BarCode" --include="*.cs" .
grep -r "BarCodeControl\|Code128Generator\|QRCodeGenerator\|DataMatrixGenerator\|PDF417Generator\|AztecCodeGenerator" --include="*.cs" .
grep -r "barCode\.Module\|barCode\.Symbology\|DrawToBitmap\|DevExpress\.XtraPrinting\.BarCode" --include="*.cs" .
Arbeiten Sie jedes Spiel einzeln durch:
- Ersetzen Sie
using DevExpress.XtraEditors;undusing DevExpress.XtraPrinting.BarCode;durchusing IronBarCode; - Ersetzen Sie
new BarCodeControl()+ Symbologie-Setup durchBarcodeWriter.CreateBarcode(data, BarcodeEncoding.X) - Ersetzen Sie
new QRCodeGenerator()+ Symbologie-Setup durchQRCodeWriter.CreateQrCode(data, size, errorLevel) - Ersetzen Sie
barCode.Module = Xdurch.ResizeTo(width, height) - Ersetzen Sie
DrawToBitmap+bitmap.Save-Muster durch.SaveAsPng(path) - Ersetzen Sie Bitmap-zu-MemoryStream-Muster durch
.ToPngBinaryData() - Fügen Sie
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"beim Start der Anwendung hinzu - Fügen Sie
BarcodeReader.Read()-Aufrufe hinzu, wo immer Lesefähigkeit benötigt wird
Wenn ein Projekt DevExpress nur für Barcode-Steuerelemente und keine anderen DX-Komponenten verwendet, entfernen Sie die DevExpress NuGet Pakete, nachdem alle Barcode-Referenzen ersetzt wurden. Wenn das Projekt DevExpress-Grid-, Diagramm- oder andere UI-Steuerelemente verwendet, lassen Sie diese Pakete an Ort und Stelle – diese Migration betrifft nur den Barcode-Code.
Häufig gestellte Fragen
Warum sollte ich von DevExpress BarCode auf IronBarcode umsteigen?
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 DevExpress-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 DevExpress BarCode 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.
Müssen während der Migration sowohl DevExpress Barcode als auch IronBarcode installiert bleiben?
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 zu DevExpress BarCode?
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 nach der Migration von DevExpress automatisch alle Barcode-Formate?
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 DevExpress Barcode 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.

