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 getOptimalPreviewSizeByAspectRatioAndVideoHeight(List<Camera.Size> sizes, double aspectRatio, int maxHeight) { 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) && (size.height <= maxHeight)) || ((optimalSize != null) && (optimalSize.height < size.height) && (size.height <= maxHeight))) { optimalSize = size; } } return optimalSize; } }