Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get 720p Android Camera Preview Data?

Tags:

I want to use the camera preview for image recognition. For my purposes, I need the preview resolution to be as high as possible (and, at the same time, display the preview to the user).

I created a Preview class, extending SurfaceView and set the PreviewSize to 1280x720. I added a PreviewCallBack to get the live Image:

camera = Camera.open();

parameters = camera.getParameters();
parameters.setPreviewSize(1280,720);

camera.setParameters( parameters);
byte[] b = new byte[camera.getParameters().getPreviewSize().width *
  camera.getParameters().getPreviewSize().height *
  ImageFormat.getBitsPerPixel(camera.getParameters().getPreviewFormat()) / 8];
camera.addCallbackBuffer(b);
camera.setPreviewCallbackWithBuffer(new CameraPreviewCallback());

try {
 camera.setPreviewDisplay(this.getHolder());
 camera.startPreview()
}

My Byte Array b is 1382400 Byte and my CameraPreviewCallback.onPreviewFrame() function receives those 1382400 Bytes - but only the first 497664 Byte contain data (matching a 768x432 resolution (HTC Desire)).

I tested this on different devices, all with display resolutions of 800x480 (HTC Desire, LG Optimus 3D, Samsung Galaxy S2, Samsung Galaxy Tab, ...). The only device my Code works for is a HTC Desire HD.

Does anyone know how to receive the full 720p resolution as a Byte Array? "Something" seems to reduce the preview resolution to fit the smartphone display.

Regards

Joern