DevExpress BarcodeからIronBarcodeへの移行
DevExpressのグリッド、チャート、スケジューラー、ピボットコントロールを使用している場合は、それらをそのまま使用してください。 このマイグレーションは、バーコードを読むことができ、ヘッドレスで実行でき、UIコンテキスト外でデプロイできるライブラリでBarCodeControlを置き換えることに特化しています。 WinFormsまたはBlazorアプリケーションで使用しているDevExpress UIコントロールは、今回の移行の影響を受けません。 バーコード固有のコードのみが変更されます。
この移行を促す典型的なシナリオは、次の3つのいずれかです。読み取り要件が発生したが、DevExpressではそれを満たすことができない。 新しいサービスでは、WinFormsアセンブリが存在しないASP.NET Coreまたはクラウド関数でバーコードを生成する必要があります。 あるいは、Suiteの更新時期が近づき、バーコード出力のためだけにフルUIツールキットを使用することの機能あたりのコスト計算が割に合わなくなる。
ステップ1: IronBarcodeをインストールする
同じプロジェクト内に他の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
ステップ2:ライセンス初期化を追加する
アプリケーションの起動時にIronBarcodeライセンスのアクティベーションを1度だけ追加します—App.xaml.cs、またはホストビルダーのいずれかに:
// 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" .
この検索結果は、まさにあなたが交換しようとしているものです。 それ以外は何もない。
コード移行の例
コード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();
}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);
}Imports IronBarCode
Public Sub GenerateCode128(data As String, outputPath As String)
BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128) _
.ResizeTo(400, 100) _
.SaveAsPng(outputPath)
End SubbarCode.Module = 0.02fのドキュメント単位のサイズ設定はなくなりました。 .ResizeTo(400, 100)はピクセルを直接受け取ります。 手動の.SaveAsPng()に置き換えられます。
QRコード生成
以前 — DevExpress QR(エラー訂正機能付き):
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);
}Imports IronBarCode
Public Sub GenerateQrCode(url As String, outputPath As String)
QRCodeWriter.CreateQrCode(url, 500, QRCodeWriter.QrErrorCorrectionLevel.Highest) _
.SaveAsPng(outputPath)
End SubQRCodeWriter.QrErrorCorrectionLevel.Highestにマップされます。 CompactionMode.AlphaNumeric設定は、コンテンツに基づいてIronBarcodeによって自動的に処理されます。
ブランドロゴ入りのQRコード(DevExpressでは不可能だった新機能):
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 patternImports 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");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 patternImports 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");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);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");
});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}");
}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 dimensionsDrawToBitmapには、事前に割り当てられたビットマップが必要です
以前のパターンは、特定のサイズの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
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のデータバインディング
WinFormsデザイナーでBarcodeWriter.CreateBarcodeに渡すことです。 IronBarcodeはWinFormsのデータバインディングには参加しません。これはUIコントロールではなく、プログラムによるAPIです。 生成されたバーコードをフォームに表示する必要がある場合、画像バイトを生成し、それらを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);
}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;net新たにインポートする項目:
// Add this
using IronBarCode;Imports IronBarCodeAPIマッピングリファレンス
| 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" .
各試合を順に進めてください。
using IronBarCode;に置き換えますnew BarCodeControl()+ シンボロジー設定をBarcodeWriter.CreateBarcode(data, BarcodeEncoding.X)に置き換えますnew QRCodeGenerator()+ シンボロジー設定をQRCodeWriter.CreateQrCode(data, size, errorLevel)に置き換えます.ResizeTo(width, height)に置き換えますDrawToBitmap+.SaveAsPng(path)に置き換えます- ビットマップからメモリストリームへのパターンを
.ToPngBinaryData()に置き換えます - アプリケーションの起動時に
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"を追加します - 読み取り機能が必要な場所に
BarcodeReader.Read()コールを追加します
プロジェクトでDevExpressをバーコード制御のみに使用し、その他のDXコンポーネントを使用していない場合は、すべてのバーコード参照を置き換えた後、DevExpress NuGetパッケージを削除してください。 プロジェクトでDevExpressのグリッド、チャート、またはその他のUIコントロールを使用している場合は、それらのパッケージはそのままにしておいてください。今回の移行ではバーコードコードのみが影響を受けます。

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