Reputation: 585
I'm developing an app with a custom camera. Everything works fine in Motorola Moto G but when I try to save the pictures taken by a Galaxy S4, it takes this aspect:
CameraSurface.java
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Size previewSize = determinePreviewSize(true, width, height);
Camera.Parameters parameters = camera.getParameters();
camera.setDisplayOrientation(90);
parameters.setPreviewSize(previewSize.width, previewSize.height);
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
Camera.Size size = sizes.get(0);
for (int i = 0; i < sizes.size(); i++) {
if (sizes.get(i).width > size.width)
size = sizes.get(i);
}
parameters.setPictureSize(size.width,size.height);
parameters.set("display_mode","portrait");
camera.setParameters(parameters);
camera.startPreview();
}
Upvotes: 2
Views: 367
Reputation: 585
I've found myself the solution for the problem described above.
When you set setPreviewSize and setPictureSize they MUST have the same aspect ratio. If your method determinePreviewSize(true, width, height) returns a size with aspect ratio 16:9 you need to setPictureSize a resolution with the SAME aspect ratio 16:9.
So the solution is to implement a method which selects from getSupportedPictureSizes() the best resolution that matches the aspect ratio given by determinePreviewSize(true, width, height)
Upvotes: 2