DevExpress Barkod'dan IronBarcode'a Geçiş
Grid, grafik, zamanlayıcı veya pivot kontrolleri için DevExpress kullanıyorsanız, bunları tutun. Bu geçiş, BarCodeControl'i başsız çalışabilen, UI bağlamı dışında dağıtılabilen ve barkodları okuyabilen bir kütüphane ile değiştirmek hakkındadır. WinForms veya Blazor uygulamanız için güvendiğiniz DevExpress UI kontrolleri bu geçişten etkilenmez. Yalnızca barkodla ilgili kod değişir.
Bu geçişi gerektiren tipik senaryo üç şeyden biridir: bir okuma gerekliliği ortaya çıkar ve DevExpress bunu karşılayamaz; yeni bir servis, WinForms derlemelerinin olmadığı bir ASP.NET Core veya bulut fonksiyonunda barkod üretimi gerektirir; veya süit yenilemesi yaklaşır ve yalnızca barkod çıktısı için tam bir UI araç seti kullanmanın maliyet-başına-özellik matematiği artık mantıklı gelmez.
Adım 1: IronBarcode'u Kurun
Aynı projede başka DevExpress kontrolleri bulunduruyorsanız, DevExpress NuGet paketlerini yerinde bırakın. Yalnızca kaynak dosyalarınızdaki barkodla ilgili kod değişir. DevExpress'ün belirli bir projede görünmesinin tek nedeni barkod üretimiyse ve orada başka DX kontrolleri kullanmıyorsanız, geçişten sonra DevExpress paketlerini o projeden kaldırabilirsiniz:
# Only remove DevExpress packages if no other DX controls are used in this project
dotnet remove package DevExpress.Win.Navigation
Adım 2: Lisans Başlatma Ekle
Uygulama başlatıldığında IronBarcode lisans aktivasyonunu bir kez ekleyin — Program.cs, App.xaml.cs veya ana bilgisayarınızı inşa edicinizde:
// 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"Ağ çağrısı yok. Kontrol edilecek hata kodu yok. Yerel doğrulama.
Adım 3: Barkoda Özgü Kodu Değiştirin
Kod tabanınızda DevExpress barkod tiplerini arayın. Diğer her şey kalır:
# 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" .
Bu aramanın sonuçları tam olarak neyi değiştireceğinizdir. Başka bir şey yok.
Kod Göç Örnekleri
Code 128 Üretimi
Bu, en yaygın geçiştir. BarCodeControl ile Code128Generator sembolojisi bir tek BarcodeWriter.CreateBarcode çağrısına dönüşür.
Öncesi — DevExpress WinForms kontrolü:
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 SubSonrası — 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 döküman-birimi boyutlandırması kalktı. .ResizeTo(400, 100), pikselleri doğrudan alır. Manuel Bitmap tahsisi ve DrawToBitmap çağrısı, boyutlandırmayı otomatik olarak halleden .SaveAsPng() ile değiştirildi.
QR Kod Oluşturma
Öncesi — Hata düzeltmeli 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 SubSonrası — 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 SubQRCodeErrorCorrectionLevel.H, QRCodeWriter.QrErrorCorrectionLevel.Highest'a eşlenir. CompactionMode.AlphaNumeric ayarı, içeriğe göre IronBarcode tarafından otomatik olarak ele alınır.
Marka logosu ile QR kod (net yeni yetenek — DevExpress ile mümkün değil):
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 SubData Matrix Üretimi
Önce — 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 patternSonrası — 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 Üretimi
Önce — 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 patternSonrası — 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")Okuma Ekleyin (Net Yeni Yetenek)
DevExpress bir okuma API'si sağlamaz. Bir okuma gereksinimi geldiyse, IronBarcode burada kendini hemen öder:
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 Barkod Uç Noktası
Bu, WinForms çözümleri olmadan BarCodeControl ile mümkün değildi. IronBarcode bunu doğal olarak destekler:
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'lerden Barkod Okuma
IronBarcode, PDF dosyalarından yerel olarak okur. PdfiumViewer yok, render döngüsü yok, ek paketler yok:
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}")
NextYaygın Geçiş Sorunları
barCode.Module Belge Birimlerini Kullanır, Pikseli Değil
barCode.Module, belgedeki en dar çubuğun genişliğini kontrol eder (render DPI bağlamına bağlıdır). Bu bir piksel sayısı değildir. Geçiş sırasında, modül değerini piksellere dönüştürmeye çalışmayın - bunun yerine, hangi piksel boyutlarını istediğinize karar verin ve doğrudan .ResizeTo(width, height) kullanın.
// 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, Önceden Ayrılmış Bitmap Gerektirir
Eski model, belirli bir boyuttaki bir Bitmap tahsis ederdi, ardından bunu render etmek için DrawToBitmap çağrılırdı. IronBarcode'un .SaveAsPng() bunu dahili olarak halleder. Önceden herhangi bir şey tahsis etmezsiniz.
// 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 Veri Bağlama
BarCodeControl bir WinForms tasarımcısında bir veri kaynağına bağlıysa, IronBarcode eşdeğeri, değeri modelinizden açıkça okumak ve BarcodeWriter.CreateBarcode 'a geçmektir. IronBarcode, WinForms veri bağlamasında yer almaz — bu bir programatik API, bir UI kontrolü değil. Oluşturulan barkodu bir formda göstermeniz gerekiyorsa, görüntü baytlarını oluşturun ve bir PictureBox üzerinde ayarlayın:
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 SubAd Alanı Değiştirme
Kaldırılacak eski ithalatlar:
// Remove these
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.BarCode;netEklenecek yeni ithalat:
// Add this
using IronBarCode;Imports IronBarCodeAPI Eşleme Başvurusu
| DevExpress Barkod | IronBarcode Eşdeğeri |
|---|---|
new BarCodeControl() | Statik — örnek yok |
new Code128Generator() + barCode.Symbology = symbology | BarcodeEncoding.Code128 parametresi |
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 | İlk argüman CreateBarcode veya CreateQrCode |
barCode.Module = 0.02f | .ResizeTo(width, height) piksellerde |
barCode.ShowText = true | .AddBarcodeText() |
DrawToBitmap(bitmap, rect) | .SaveAsPng(path) |
new Bitmap(w, h) + manuel imha | Gerekli değil |
Bitmap → MemoryStream → HTTP | .ToPngBinaryData() |
| Okuma API'si yok | BarcodeReader.Read(path) |
using DevExpress.XtraEditors + using DevExpress.XtraPrinting.BarCode | using IronBarCode |
Geçiş Kontrol Listesi
Güncellenmesi gereken tüm dosyaları bulmak için bu grep desenini kullanın:
grep -r "BarCodeControl\|Code128Generator\|QRCodeGenerator\|DataMatrixGenerator\|PDF417Generator\|AztecCodeGenerator" --include="*.cs" .
grep -r "barCode\.Module\|barCode\.Symbology\|DrawToBitmap\|DevExpress\.XtraPrinting\.BarCode" --include="*.cs" .
Her bir eşleşme üzerinde çalışın:
using DevExpress.XtraEditors;veusing DevExpress.XtraPrinting.BarCode;'iusing IronBarCode;ile değiştirinnew BarCodeControl()+ semboloji kurulumunuBarcodeWriter.CreateBarcode(data, BarcodeEncoding.X)ile değiştirinnew QRCodeGenerator()+ semboloji kurulumunuQRCodeWriter.CreateQrCode(data, size, errorLevel)ile değiştirinbarCode.Module = X'i.ResizeTo(width, height)ile değiştirinDrawToBitmap+bitmap.Savemodelini.SaveAsPng(path)ile değiştirin- Bitmap-to-MemoryStream modelini
.ToPngBinaryData()ile değiştirin - Uygulama başlatıldığında
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"ekleyin - Okuma becerisinin gerektiği her yerde
BarcodeReader.Read()çağrıları ekleyin
Bir proje, yalnızca barkod kontrolleri için DevExpress kullanıyorsa ve başka DX bileşenleri kullanmıyorsa, tüm barkod referansları değiştirildikten sonra DevExpress NuGet paketlerini kaldırın. Proje, DevExpress grid, grafik veya diğer UI kontrollerini kullanıyorsa, bu paketleri yerinde bırakın — bu geçiş yalnızca barkod kodunu etkiler.

Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapılandırılmış, görsel olarak çekici kılavuzlar oluşturmayı seviyor.