Java tutorial
//package com.java2s; //License from project: Apache License import android.hardware.Camera; import java.util.List; public class Main { private static final double ASPECT_TOLERANCE = 0.05; public static Camera.Size getOptimalPreviewSizeByAspectRatio(List<Camera.Size> sizes, double aspectRatio) { if (sizes == null) return null; Camera.Size optimalSize = null; // Find size for (Camera.Size size : sizes) { double ratio = (double) size.width / size.height; if (Math.abs(ratio - aspectRatio) > ASPECT_TOLERANCE) { continue; } if ((optimalSize == null) || (optimalSize.height < size.height)) { optimalSize = size; } } return optimalSize; } }