Java tutorial
//package com.java2s; //License from project: Open Source License import android.hardware.Camera.Size; import android.util.Log; import java.util.List; public class Main { private static final String TAG = "CameraHelper"; public static Size getMaxPreviewSize(List<Size> sizes, List<Size> vSize) { if (sizes == null) { return null; } Size optimalSize = null; int maxHeight = 0; int maxWidth = 0; for (Size size : sizes) { if (size.height > maxHeight) { if (vSize == null) { optimalSize = size; maxHeight = size.height; maxWidth = size.width; continue; } if (vSize.contains(size)) { optimalSize = size; maxHeight = size.height; maxWidth = size.width; } } else if (size.width > maxWidth) { if (vSize == null) { optimalSize = size; maxWidth = size.width; continue; } if (vSize.contains(size)) { optimalSize = size; maxWidth = size.width; } } } Log.e(TAG, "width:" + optimalSize.width + "height:" + optimalSize.height); return optimalSize; } }