1

我尝试使用以下代码片段从图像中读取 IMB 条形码,但它始终返回 null。我也尝试过在下面的黑盒测试中使用 IMB 条形码图像,但不起作用。

https://github.com/micjahn/ZXing.Net/tree/master/Source/test/data/blackbox/imb-1

private static void Decode()
{
    Bitmap bitmap = new Bitmap(@"\07.png");
    try
    {
        MemoryStream memoryStream = new MemoryStream();
        bitmap.Save(memoryStream, ImageFormat.Bmp);
        byte[] byteArray = memoryStream.GetBuffer();
        ZXing.LuminanceSource source = new RGBLuminanceSource(byteArray, bitmap.Width, bitmap.Height);
        var binarizer = new HybridBinarizer(source);
        var binBitmap = new BinaryBitmap(binarizer);
        IMBReader imbReader = new IMBReader();

        Result str = imbReader.decode(binBitmap);

    }
    catch { }

}
4

1 回答 1

0

我已经通过使用通过以下链接共享的以下代码片段解决了这个问题。 https://github.com/micjahn/ZXing.Net/issues/59

private static void Decode2()
{
    var bitmap = new Bitmap(@"\07.png"); // make sure that the file exists at the root level
    try
    {
        var imbReader = new BarcodeReader
        {
            Options =
            {
                PossibleFormats = new List<BarcodeFormat> {BarcodeFormat.IMB}
            }
        };
        var result = imbReader.Decode(bitmap);
        if (result != null)
            System.Console.WriteLine(result.Text);
        else
            System.Console.WriteLine("nothing found");
    }
    catch (System.Exception exc)
    {
        System.Console.WriteLine(exc.ToString());
    }
}
于 2017-11-20T04:11:44.297 回答