IronBarcode가 MSI 바코드를 인식할 수 없음
문제
IronBarcode 라이브러리를 사용하여 MSI BARCODE를 생성할 때, BarcodeReader.Read 메서드가 생성된 MSI BARCODE를 읽지 못하는 경우가 있어, 스캔 결과가 비어 있고 BARCODE에서 예상된 값이 나오지 않는 경우가 있습니다.
해결책
BarcodeReader.Read가 MSI BarCode를 읽을 수 있도록 하려면, Read 메서드에 보조 선택 매개변수인 BarcodeReaderOptions를 제공해야 합니다. BarcodeReaderOptions 내에서 ExpectedBarcodeTypes 값을 할당하여 읽으려는 BARCODE 유형을 명시적으로 지정합니다. 이렇게 하면 Read 메서드는 IronBarcode에서 생성된 MSI BARCODE는 물론 외부 MSI BARCODE도 인식할 수 있습니다.
다음은 BarcodeReaderOptions을 BarcodeReader.Read에 적용하는 간단한 예시입니다.
코드 예제
// 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
예제에서 먼저 새로운 BarcodeReaderOptions 변수를 인스턴스화한 다음, ExpectedBarcodeTypes에 BarcodeEncoding.MSI 열거형을 할당하여 IronBarcode가 대신 MSI BarCode를 처리하도록 지시합니다. 그 후, barcodeResults가 BarcodeResults 배열을 반환하므로 for 루프를 사용하여 BARCODE 값(12345)을 PRINT하고, 각 결과에 대해 텍스트 값을 확인합니다.

