IronBarcode MSI Barkodu Tanıyamadı
Sorun
IronBarcode kütüphanesini kullanarak bir MSI BARCODE oluştururken, BarcodeReader.Read yönteminin oluşturulan MSI BARCODE'u okuyamadığı durumlar olabilir; bu da taramanın boş çıkmasına ve BARCODE'dan beklenen değerin alınamamasına neden olur.
Çözüm
BarcodeReader.Read'nin MSI BARCODE'ını okuyabilmesini sağlamak için, Read yöntemi için ikincil isteğe bağlı BarcodeReaderOptions parametresini sağlamalıyız. BarcodeReaderOptions içinde, ExpectedBarcodeTypes değerini atayarak okumaya çalıştığımız BarCode türünü açıkça belirtiriz. Bu şekilde, Read yöntemi, IronBarcode'dan oluşturulan MSI BarCode'un yanı sıra herhangi bir harici MSI BarCode'u da tanıyacaktır.
Aşağıda, BarcodeReaderOptions'nin BarcodeReader.Read'ye nasıl uygulanacağına dair kısa bir örnek verilmiştir.
Kod Örneği
// Creating MSI Barcode with the value "12345"
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI);
// Save barcode as image
myBarcode.SaveAsImage("msi.png");
// Reading MSI
var barcodeReaderOptions = new BarcodeReaderOptions
{
// Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically
ExpectBarcodeTypes = BarcodeEncoding.MSI,
};
// Read barcode with additional barcodeReaderOptions from above
var barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions);
// Using a for loop and print out the result
foreach (BarcodeResult result in barcodeResults)
{
Console.WriteLine(result.Text);
// Output: 12345
}
// Creating MSI Barcode with the value "12345"
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI);
// Save barcode as image
myBarcode.SaveAsImage("msi.png");
// Reading MSI
var barcodeReaderOptions = new BarcodeReaderOptions
{
// Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically
ExpectBarcodeTypes = BarcodeEncoding.MSI,
};
// Read barcode with additional barcodeReaderOptions from above
var barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions);
// Using a for loop and print out the result
foreach (BarcodeResult result in barcodeResults)
{
Console.WriteLine(result.Text);
// Output: 12345
}
' Creating MSI Barcode with the value "12345"
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI)
' Save barcode as image
myBarcode.SaveAsImage("msi.png")
' Reading MSI
Dim barcodeReaderOptions As New BarcodeReaderOptions With {.ExpectBarcodeTypes = BarcodeEncoding.MSI}
' Read barcode with additional barcodeReaderOptions from above
Dim barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions)
' Using a for loop and print out the result
For Each result As BarcodeResult In barcodeResults
Console.WriteLine(result.Text)
' Output: 12345
Next result
Örnekte, önce yeni bir BarcodeReaderOptions değişkeni oluşturuyoruz, ardından ExpectedBarcodeTypes'ye BarcodeEncoding.MSI enum'unu atayarak IronBarcode'a bunun yerine MSI BarCode'unu beklemesi talimatını veriyoruz. Ardından, barcodeResults bir BarcodeResults dizisi döndürdüğü için, bir for döngüsü içinde BARCODE'un değerini (12345) PRINT ederiz ve metin değeri için her sonucu döngüye alırız.

