private Camera.Size calBestPreviewSize(Camera.Parameters camPara, final int width, final int height) { List allSupportedSize = camPara.getSupportedPreviewSizes(); ArrayList widthLargerSize = new ArrayList(); for (Camera.Size tmpSize : allSupportedSize) { if (tmpSize.width > tmpSize.height) { widthLargerSize.add(tmpSize); } } Collections.sort(widthLargerSize, new Comparator() { @Override public int compare(Camera.Size lhs, Camera.Size rhs) { int off_one = Math.abs(lhs.width * lhs.height - width * height); int off_two = Math.abs(rhs.width * rhs.height - width * height); return off_one - off_two; } }); return widthLargerSize.get(0); }