I am working on an Android app that uses the phone’s camera and I’m using a custom code.
The problem is that the image is showing in the preview is not correct (the image aspect ratio is not OK).
If I use the following code:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Camera.Parameters params = mCamera.getParameters();
List<Camera.Size> sizes = params.getSupportedPreviewSizes();
Camera.Size selected = sizes.get(0);
params.setPreviewSize(selected.width,selected.height);
mCamera.setParameters(params);
mCamera.startPreview();
the preview image is OK (I think little part of the image top and bottom is not showed).
The problem then is that the captured image showed after takePicture method is called is not showed correctly (the image aspect ratio is not OK, the image appears to be compressed into the view), even so if I save the picture to a file image appears to be OK.
I wonder if it is possible to show the image correctly in both cases. Suggestions?
The solution was easy, but I didn’t know I must set correct aspect ratio MANUALLY (it is not an automatic process, I supposed it was and this step it is not explained in most how to’s). Finally, I solved it this way:
Getting supported sizes using
params.getSupportedPreviewSizes()andparams.getSuppertedPictureSize().Computing the best aspect ratio (width/height) according to the measures
widthandheightpassed insurfaceChanged(SurfaceHolder holder, int format, int width, int height).Setting the best preview size and picture size using
setPreviewSizeandsetPictureSize, respectively, beforestartPreview()method is called.