Get the preview size that fits within the given width and height and has the largest area - Android Camera

Android examples for Camera:Camera Preview

Description

Get the preview size that fits within the given width and height and has the largest area

Demo Code


//package com.java2s;

import android.hardware.Camera;

public class Main {

    public static Camera.Size getBestPreviewSized(int width, int height,
            Camera.Parameters parameters) {
        Camera.Size result = null;//from  w  ww. ja  va  2 s .  com

        for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
            if (size.width <= width && size.height <= height) {
                if (result == null) {
                    result = size;
                } else {
                    int resultArea = result.width * result.height;
                    int newArea = size.width * size.height;

                    if (newArea > resultArea) {
                        result = size;
                    }
                }
            }
        }

        return (result);
    }
}

Related Tutorials