givi
givi

Reputation: 1903

Different sizes of camera preview on Android

I'm developing an application that performs image processing on the native side and it receives camera data for each frame from Java side.

The problem is that it takes really lot of time to copy the image from JVM memory to my native one.

Question: is it possible to use different preview sizes, i.e. bigger size to display video frame on the SurfaceView and another smaller one for processing.

Upvotes: 2

Views: 2277

Answers (1)

DeeV
DeeV

Reputation: 36035

Generally, you would use the setPreviewSize() method of the Camera.Parameters class.

Something like this:

...
Camera.Parameters mParams = camera.getParameters();
List<Camera.Size> previewSizes = mParams.getSupportedPreviewSizes();
Camera.Size previewSize = previewSizes.get(previewSizes.size()-1);
mParams.setPreviewSize(previewSize.width, previewSize.height);
mParams.setPreviewFrameRate(15); // get 15 preview frames per second
camera.setParameters(mParams);
...

Where camera is the Camera object displaying the image.

I have this in the surfaceChanged method of the SurfaceView. This will change the preview size that you get in the Camera.PreviewCallback implementation that captures the camera's YUV image (or bitmap image if you're lucky enough to have a phone that uses it). It doesn't affect the image that is shown on screen.

Upvotes: 0

Related Questions