2017-11-18 119 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