Created
January 7, 2021 05:40
-
-
Save osamaqarem/c4901513253100b295641486d24f7a57 to your computer and use it in GitHub Desktop.
Calculate Closest Aspect Ratio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Camera.Size calBestPreviewSize(Camera.Parameters camPara, | |
final int width, final int height) { | |
List<Camera.Size> allSupportedSize = camPara.getSupportedPreviewSizes(); | |
ArrayList<Camera.Size> widthLargerSize = new ArrayList<Camera.Size>(); | |
for (Camera.Size tmpSize : allSupportedSize) { | |
if (tmpSize.width > tmpSize.height) { | |
widthLargerSize.add(tmpSize); | |
} | |
} | |
Collections.sort(widthLargerSize, new Comparator<Camera.Size>() { | |
@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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment