get Camera Best Size On Ratio - Android Camera

Android examples for Camera:Camera Size

Description

get Camera Best Size On Ratio

Demo Code


//package com.java2s;

import java.util.List;
import android.hardware.Camera.Size;

public class Main {
    private static Size getBestSizeOnRatio(double sourceRatio,
            List<Size> supportedSizes) {
        Size bestSize = null;/*from   ww w  . j a  v  a  2  s  .c  o m*/
        double lastDiff = Double.MAX_VALUE;

        for (Size size : supportedSizes) {
            double supportedRatio = size.width / size.height;

            double diff = Math.abs(sourceRatio - supportedRatio);
            if (diff < lastDiff) {
                bestSize = size;
                lastDiff = diff;
            }
        }

        return bestSize;
    }
}

Related Tutorials