When trying to convert the byte[] of Camera.onPreviewFrame to Bitamp using BitmapFactory.decodeByteArray gives me an error SkImageDecoder::Factory returned null
Following is my code:
public void onPreviewFrame(byte[] data, Camera camera) {
Bitmap bmp=BitmapFactory.decodeByteArray(data, 0, data.length);
}
I found the answer after a long time. Here it is…
Instead of using
BitmapFactory, I used my custom method to decode thisbyte[] datato a valid image format. To decode the image to a valid image format, one need to know what picture format is being used by the camera by callingcamera.getParameters().getPictureFormat(). This returns a constant defined byImageFormat. After knowing the format, use the appropriate encoder to encode the image.In my case, the
byte[] datawas in theYUVformat, so I looked forYUVtoBMPconversion and that solved my problem.