0

My Android camera is passing through an entire image into onPreviewFrame, but I only want the bytes that correspond to a pixel range. For instance an image that is 480x640 in pixels is passed through. I want a new byte[] Array with the pixels in the the range of Rect(100,100,200,200)

public void onPreviewFrame(byte[] arg0, Camera arg1) {
    // arg0 = 460,800 BYTES
    // the camera's resolution is at 640 x 480
    // arg0 format is NV21
}
Alex Bedro
  • 96
  • 7
  • Possible duplicate: http://stackoverflow.com/questions/9656350/android-camera-how-can-i-take-a-specific-rectangle-from-the-byte-array. The word you are looking for is "cropping." – Robert Harvey Aug 15 '12 at 18:40
  • Also http://stackoverflow.com/questions/9747295/crop-particular-part-of-image-in-android – Robert Harvey Aug 15 '12 at 18:41

1 Answers1

0

Try using http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html

and the method newInstance(InputStream stream, boolean isShareable) of the BitmapRegionDecoder class.And next You can use

BitmapRegionDecoder decoder = newInstance(stream,false)
Bitmap region = decoder.decodeRegion(new Rect(x, y, x1, y1), null);
G_S
  • 7,068
  • 2
  • 21
  • 51
  • I tried using this method but it only supports JPEG & PNG picture formats and my android camera doesn't support either. But thanks anyways! – Alex Bedro Aug 16 '12 at 15:35