I am trying to get a Bitmap Image from Camera Preview on which I am going to do some processing and draw some overlays after performing Face detection.
After looking around, I found out that the byte array that onPreviewFrame takes cannot be decoded into a bitmap directly, it needs to be converted to the correct pixel format using YuvImage, and that's exactly what I did:
@Override
public void onPreviewFrame(byte[] data, Camera camera)
{
YuvImage temp = new YuvImage(data, camera.getParameters().getPreviewFormat(), camera.getParameters().getPictureSize().width, camera.getParameters().getPictureSize().height, null);
ByteArrayOutputStream os = new ByteArrayOutputStream();
temp.compressToJpeg(new Rect(0, 0, temp.getWidth(), temp.getHeight()), 80, os);
Bitmap preview = BitmapFactory.decodeByteArray(os.toByteArray(), 0, os.toByteArray().length);
/* DO SOMETHING WITH THE preview */
}
The problem is, the 'preview' object is not null, but it's aparently not a valid Bitmap. On the debugger I can see that mWidth and mHeight are both set to -1 which seems wrong to me. What am I doing wrong?