2012-08-15 49 views
0

我的Android相機正在將整個圖像傳遞到onPreviewFrame,但我只想要與像素範圍對應的字節。 例如,像素爲480x640的圖像通過。我想與在矩形的(100100200200)如何解析圖像字節[]數組

public void onPreviewFrame(byte[] arg0, Camera arg1) { 
    // arg0 = 460,800 BYTES 
    // the camera's resolution is at 640 x 480 
    // arg0 format is NV21 
} 
+0

可能重複:http://stackoverflow.com/questions/9656350/android-camera-how-can-i-take-a-specific-rectangle-from-the-byte-陣列。你正在尋找的詞是「種植」。 – 2012-08-15 18:40:53

+0

也http://stackoverflow.com/questions/9747295/crop-particular-part-of-image-in-android – 2012-08-15 18:41:18

回答

0

的範圍中的像素的新的字節[]數組使用http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html

和BitmapRegionDecoder類的方法的newInstance(InputStream的流,布爾isShareable)嘗試。而接下來你可以使用

BitmapRegionDecoder decoder = newInstance(stream,false) 
Bitmap region = decoder.decodeRegion(new Rect(x, y, x1, y1), null); 
+0

我試過使用這種方法,但它只支持JPEG和PNG圖片格式,我的Android相機不支持無論是。不過謝謝你! – 2012-08-16 15:35:36