Android Utililty Methods Camera Size Get

List of utility methods to do Camera Size Get

Description

The list of methods to do Camera Size Get are organized into topic(s).

Method

SizegetBestAspectPreviewSize(int displayOrientation, int width, int height, Camera.Parameters parameters, double closeEnough)
get Best Aspect Preview Size
double targetRatio = (double) width / height;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
if (displayOrientation == 90 || displayOrientation == 270) {
    targetRatio = (double) height / width;
List<Size> sizes = parameters.getSupportedPreviewSizes();
Collections.sort(sizes,
...
SizegetLargestPictureSize(CameraHost host, Camera.Parameters parameters)
get Largest Picture Size
Size result = null;
for (Size size : parameters.getSupportedPictureSizes()) {
    if (size.height <= host.getDeviceProfile()
            .getMaxPictureHeight()
            && size.height >= host.getDeviceProfile()
                    .getMinPictureHeight()) {
        if (result == null) {
            result = size;
...
SizegetOptimalPreviewSize(int displayOrientation, int width, int height, Camera.Parameters parameters)
get Optimal Preview Size
double targetRatio = (double) width / height;
List<Size> sizes = parameters.getSupportedPreviewSizes();
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = height;
if (displayOrientation == 90 || displayOrientation == 270) {
    targetRatio = (double) height / width;
for (Size size : sizes) {
    double ratio = (double) size.width / size.height;
    if (Math.abs(ratio - targetRatio) <= ASPECT_TOLERANCE) {
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
if (optimalSize == null) {
    minDiff = Double.MAX_VALUE;
    for (Size size : sizes) {
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
return (optimalSize);
SizegetSmallestPictureSize(Camera.Parameters parameters)
get Smallest Picture Size
Size result = null;
for (Size size : parameters.getSupportedPictureSizes()) {
    if (result == null) {
        result = size;
    } else {
        int resultArea = result.width * result.height;
        int newArea = size.width * size.height;
        if (newArea < resultArea) {
...
Camera.SizegetPreviewSize(Camera.Parameters cp)
get Preview Size
Camera.Size size = cp.getPreferredPreviewSizeForVideo();
if (size == null)
    size = cp.getSupportedPreviewSizes().get(0);
return size;
SizegetSizeLB(List sizes, int w, int h)
get Size LB
Size re = null;
int wantSize = w * h;
int minGap = wantSize;
for (Size size : sizes) {
    if (getSizeGapValue(size, wantSize) > 0
            && getSizeGapValue(size, wantSize) < minGap) {
        re = size;
        minGap = getSizeGap(size, wantSize);
...
SizegetSizeRATIO(List sizes, int w, int h)
get Size RATIO
Size re = null;
double wantRatio = (double) w / (double) h;
double minGap = wantRatio;
for (Size size : sizes) {
    if (getRatioGap(size, wantRatio) < minGap) {
        minGap = getRatioGap(size, wantRatio);
        re = size;
return re;
SizegetSizeSIZE(List sizes, int w, int h)
get Size SIZE
Size re = null;
int wantSize = w * h;
int minGap = wantSize;
for (Size size : sizes) {
    if (getSizeGap(size, wantSize) < minGap) {
        re = size;
        minGap = getSizeGap(size, wantSize);
return re;
SizegetSizeWIDTH(List sizes, int w, int h)
get Size WIDTH
int wantWidth = w;
Size re = null;
int minGap = w;
for (Size size : sizes) {
    if (getWidthGap(size, wantWidth) < minGap) {
        minGap = getWidthGap(size, wantWidth);
        re = size;
return re;
Camera.SizegetOptimalPreviewSize( List sizes, int w, int h)
Iterate over supported camera preview sizes to see which one best fits the dimensions of the given view while maintaining the aspect ratio.
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
if (sizes == null)
    return null;
Camera.Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
for (Camera.Size size : sizes) {
...