You did correct, the frame pixels are stored at the byteArray.
The problem is that this pixels array is in the NV21 format. You need to convert to Y or RGB format. You can obtain more info on how to convert here:
https://stackoverflow.com/questions/5272388/extract-black-and-white-image-from-android-cameras-nv21-format/12702836#12702836
If you just wanna the grayscale image you can do that:
private Bitmap getYBitmapFromPixels(byte [] pixels, int width, int height) {
Bitmap frame_bm = null;
int [] pixels_int = new int[pixels.length];
int size = width*height;
for (int i= 0 ; i<size ; i++) {
int p = pixels[i] & 0xFF;
pixels_int[i] = 0xff000000 | p<<16 | p<<8 | p;
}
frame_bm = Bitmap.createBitmap(pixels_int, width, height, Bitmap.Config.ARGB_8888);
return frame_bm;
}
Use:
Buffer UnrealB = frame.images().get(0).buffer();
byte[] byteArray = new byte[UnrealB.size()];
UnrealB.copyTo(byteArray, 0);
Bitmap bitmap = getYBitmapFromPixels(byteArray, frame.images().get(0).width(), frame.images().get(0).height());