IronBarcode가 MSI 바코드를 인식하지 못함
문제
IronBarcode 라이브러리를 사용하여 MSI 바코드를 생성할 때, BarcodeReader.Read 메서드가 생성된 MSI 바코드를 읽을 수 없는 경우가 발생하여 빈 스캔과 바코드에서 기대했던 값을 얻지 못할 수 있습니다.
해결책
BarcodeReader.Read가 MSI 바코드를 읽을 수 있도록 하기 위해, Read 메서드에 대한 보조 선택적 BarcodeReaderOptions 매개변수를 제공해야 합니다. BarcodeReaderOptions 내에서, ExpectedBarcodeTypes 값을 할당하여 우리가 읽으려고 하는 바코드 유형을 명시적으로 지정합니다. 이렇게 하면, Read 메서드는 IronBarCode에서 생성된 MSI 바코드뿐만 아니라 외부 MSI 바코드도 인식할 수 있습니다.
아래는 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 바코드를 기대하도록 지시합니다. 그 후, barcodeResults가 BarcodeResults 배열을 반환하면서 각 결과를 루프를 통해 텍스트 값을 얻도록 하여, 바코드 값 12345를 for 루프 내에서 출력합니다.

