2015-12-08 49 views
0

我正在開發一個android應用程序,它具有解碼包含二維碼的灰度圖像的要求。我一直在嘗試將zxing與android集成。對於RGB顏色比例圖像它工作正常。Zxing從灰度圖像構造二進制位圖android

對於RGB圖像字節數組我已經使用此代碼來構建二進制位圖。

RGBLuminanceSource source = new RGBLuminanceSource(width, height, data); 
BinaryBitmap Binary_bitmap = new BinaryBitmap(new HybridBinarizer(source)); 

但對於灰度圖像我不知道如何構建二進制位圖。

回答

0

我只是使用LuminanceSource沒有RGB。適用於灰度圖像,儘管我使用的是緩衝圖像。因此,這將是LuminanceSource source = new BufferedImageLuminanceSource(grayscaleImg);

如果您需要您的墊轉換爲一個緩衝的圖像,這樣做:

BufferedImage gray = new BufferedImage(mat.width(), mat.height(), BufferedImage.TYPE_BYTE_GRAY); 
byte[] data = ((DataBufferByte) gray.getRaster().getDataBuffer()).getData(); 
mat.get(0, 0, data);