IMB barcode could not be read

懵懂的女人 提交于 2020-02-23 03:56:06

问题


I have tried to read IMB barcode from an image with the below code snippet, but it always return null. I have also tried with the IMB barcode images in the blackbox testing below, but doesn't work.

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 { }

}

回答1:


I have solved this problem by using the below code snippet shared through the below link. 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());
    }
}


来源:https://stackoverflow.com/questions/47364550/imb-barcode-could-not-be-read

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!