How to Read Multiple Barcodes at Once in C#
从DevExpress条形码迁移到IronBarcode
如果您使用 DevExpress 的网格、图表、调度程序或透视表控件,请保留这些控件。 此迁移专门用于将BarCodeControl替换为一个可以读取条形码、无头运行并在UI上下文之外部署的库。 本次迁移不会影响您在 WinForms 或Blazor应用程序中使用的 DevExpress UI 控件。 只有条形码特定的代码会发生变化。
导致这种迁移的典型场景有以下三种情况之一:出现读取需求,而 DevExpress 无法满足该需求; 一项新服务需要在ASP.NET Core或云函数中生成条形码,但其中不存在 WinForms 程序集; 或者,当Suite续订时,仅仅为了条形码输出而使用完整的 UI 工具包,其每项功能的成本计算就变得不划算了。
步骤 1:安装IronBarcode
dotnet add package BarCode
如果同一项目中保留了其他 DevExpress 控件,请保留 DevExpress NuGet包。 只有源文件中与条形码相关的代码会发生变化。 如果条形码生成是 DevExpress 出现在特定项目中的唯一原因,并且您在该项目中没有使用其他 DX 控件,则可以在迁移后从该项目中删除 DevExpress 包:
# 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
步骤 2:添加许可证初始化
在应用程序启动时添加IronBarcode许可激活,一次在App.xaml.cs或您的主机构建器中:
// 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"
无网络通话。 没有错误代码可供检查。 本地验证。
步骤 3:替换条形码特定代码
在代码库中搜索 DevExpress 条形码类型。其他内容保持不变:
# 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" .
搜索结果正是您要替换的部件。 没有别的了。
代码迁移示例
代码 128 生成
这是最常见的迁移方式。 具有BarcodeWriter.CreateBarcode调用。
之前 — DevExpress WinForms 控件:
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
之后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
barCode.Module = 0.02f文档单位大小已消失。 .ResizeTo(400, 100)直接处理像素。 手动的.SaveAsPng()替代,从而自动处理大小调整。
二维码生成
之前 — 带有纠错功能的 DevExpress 二维码:
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
之后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
QRCodeWriter.QrErrorCorrectionLevel.Highest。 CompactionMode.AlphaNumeric设置由IronBarcode根据内容自动处理。
带有品牌标识的二维码(全新功能——DevExpress 尚不支持):
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
数据矩阵生成
之前 — 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
之后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 生成
之前 — 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
之后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")
新增阅读功能(全新功能)
DevExpress 不提供读取 API。 如果确实需要阅读相关内容,那么IronBarcode就能立即体现其价值:
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条形码端点
这在没有WinForms变通方法的情况下通过BarCodeControl无法实现。 IronBarcode原生支持此功能:
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)
从PDF文件中读取条形码
IronBarcode可以直接读取 PDF 文件。 无需 PdfiumViewer,无需渲染循环,无需额外软件包:
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
常见迁移问题
barCode.Module 使用文档单位,而非像素
barCode.Module控制文档单位中最窄条的宽度(取决于渲染DPI上下文)。 这不是像素计数。 在迁移时,不要尝试将模块值转换为像素—而是决定您想要的像素尺寸并直接使用.ResizeTo(width, height)。
// 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 需要预先分配位图
旧模式分配了特定大小的DrawToBitmap以在其中渲染。 IronBarcode的.SaveAsPng()在内部处理所有这些。 您无需预先分配任何资源。
// 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 数据绑定
如果BarcodeWriter.CreateBarcode。 IronBarcode不参与 WinForms 数据绑定——它是一个程序化 API,而不是一个 UI 控件。 如果需要在表单上显示生成的条形码,则生成图像字节并将其设置到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
命名空间替换
要移除的旧导入项:
// Remove these
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
// Remove these
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;
新增导入项:
// Add this
using IronBarCode;
// Add this
using IronBarCode;
Imports IronBarCode
API 映射参考
| DevExpress 条形码 | IronBarcode等效物 |
|---|---|
new BarCodeControl() |
静态 — 无实例 |
new Code128Generator() + barCode.Symbology = symbology |
BarcodeEncoding.Code128参数 |
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 |
CreateQrCode的第一个参数 |
barCode.Module = 0.02f |
.ResizeTo(width, height)以像素为单位 |
barCode.ShowText = true |
.AddBarcodeText() |
DrawToBitmap(bitmap, rect) |
.SaveAsPng(path) |
new Bitmap(w, h) + 手动处理 |
不需要 |
位图 → MemoryStream → HTTP |
.ToPngBinaryData() |
| 无读取 API | BarcodeReader.Read(path) |
using DevExpress.XtraEditors + using DevExpress.XtraPrinting.BarCode |
using IronBarCode |
迁移清单
使用以下 grep 模式查找所有需要更新的文件:
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" .
逐场比赛进行分析:
- 用
using DevExpress.XtraPrinting.BarCode; - 用
new BarCodeControl()+ 符号设置 - 用
new QRCodeGenerator()+ 符号设置 - 用
barCode.Module = X - 用
DrawToBitmap+bitmap.Save模式 - 用
.ToPngBinaryData()替换位图到内存流模式 - 在应用程序启动时添加
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY" - 在需要读取功能的地方添加
BarcodeReader.Read()调用
如果一个项目仅使用 DevExpress 来处理条形码控件,而没有使用其他 DX 组件,则在替换所有条形码引用后,删除 DevExpress NuGet包。 如果项目使用了 DevExpress 网格、图表或其他 UI 控件,请保留这些包——此迁移仅涉及条形码代码。
常见问题解答
我为什么要从 DevExpress Barcode 迁移到 IronBarcode?
常见原因包括简化许可(消除 SDK + 运行时密钥的复杂性)、消除吞吐量限制、获得原生 PDF 支持、改进 Docker/CI/CD 部署以及减少生产代码中的 API 样板代码。
如何用 IronBarcode 替换 DevExpress API 调用?
用 `IronBarCode.License.LicenseKey = "key"` 替换实例创建和许可相关的样板代码。用 `BarcodeReader.Read(path)` 替换读取器调用,用 `BarcodeWriter.CreateBarcode(data, encoding)` 替换写入器调用。静态方法无需实例管理。
从 DevExpress Barcode 迁移到 IronBarcode 时,需要修改多少代码?
大多数迁移都能减少代码行数。许可样板代码、实例构造函数和显式格式配置都被移除。核心读/写操作映射到更简洁的 IronBarcode 等效代码,并生成更清晰的结果对象。
迁移过程中是否需要同时保留 DevExpress Barcode 和 IronBarcode?
不。大多数迁移都是直接替换,而不是并行操作。一次迁移一个服务类,替换 NuGet 引用,并更新实例化和 API 调用模式,然后再迁移下一个类。
IronBarcode 的 NuGet 包名称是什么?
该软件包名为“IronBarCode”(B 和 C 大写)。使用“Install-Package IronBarCode”或“dotnet add package IronBarCode”进行安装。代码中的 using 指令为“using IronBarCode;”。
与 DevExpress Barcode 相比,IronBarcode 如何简化 Docker 部署?
IronBarcode 是一个 NuGet 包,不包含任何外部 SDK 文件或已挂载的许可证配置。在 Docker 环境中,设置 IRONBARCODE_LICENSE_KEY 环境变量后,该包会在启动时自动处理许可证验证。
从 DevExpress 迁移后,IronBarcode 是否能自动检测所有条形码格式?
是的。IronBarcode 可以自动检测所有支持格式的条码符号,无需显式枚举 BarcodeTypes。如果已知条码格式且性能至关重要,BarcodeReaderOptions 允许缩小搜索范围以进行优化。
IronBarcode 能否在不使用单独库的情况下读取 PDF 中的条形码?
是的。`BarcodeReader.Read("document.pdf")` 可以直接处理 PDF 文件。结果包括每个条形码的页码、格式、值和置信度。无需外部 PDF 渲染步骤。
IronBarcode如何处理并行条码处理?
IronBarcode 的静态方法是无状态且线程安全的。可以直接对文件列表使用 Parallel.ForEach,无需进行线程级实例管理。BarcodeReaderOptions.MaxParallelThreads 控制内部线程预算。
从 DevExpress Barcode 迁移到 IronBarcode 时,结果属性会发生哪些变化?
常见重命名:BarcodeValue 变为 Value,BarcodeType 变为 Format。IronBarcode 结果还会添加 Confidence 和 PageNumber。解决方案范围内的查找替换功能会处理现有结果处理代码中的重命名。
如何在 CI/CD 流水线中设置 IronBarcode 许可?
将 IRONBARCODE_LICENSE_KEY 存储为管道密钥,并在应用程序启动代码中赋值 IronBarCode.License.LicenseKey。一个密钥即可覆盖所有环境,包括开发、测试、预发布和生产环境。
IronBarcode是否支持生成自定义样式的二维码?
是的。QRCodeWriter.CreateQrCode() 支持通过 ChangeBarCodeColor() 自定义颜色、通过 AddBrandLogo() 嵌入徽标、可配置纠错级别以及多种输出格式,包括 PNG、JPG、PDF 和流媒体。

