2017-11-18 102 views
0

我试图从下面的代码片段的图像读取IMB条码,但它总是返回null。我也在下面的黑匣子测试中尝试了IMB条形码图像,但不起作用。无法读取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 { } 

} 

回答

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()); 
    } 
} 
+0

...你从这里得到:https://github.com/micjahn/ZXing.Net/issues/59 ;) – Michael

+0

是,此代码的工作 - 感谢的解决方案。我在上述更新中添加了参考链接。 – Karthikeyan