I have gone through lot of stackoverflow threads on this topic but I did not get solution for my problem. I found a method which calcultate best PreviewSize
for your screen. For example this method--
private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.1;
double targetRatio=(double)h / w;
if (sizes == null) return null;
Camera.Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
for (Camera.Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
To the above method I have to pass screen width and height. Consider I want a picture in 1024*768 but my screen resolution is 1280*720, above method returns 1280*720 as best PreviewSize
and camera is capturing more than what actually visible in my display. Is there any way to calculate matching PreviewSize
based on required picture size.