find Closest Fps Range - Android android.hardware

Android examples for android.hardware:Close Camera

Description

find Closest Fps Range

Demo Code

import java.util.List;

import android.hardware.Camera;
import android.util.Log;

public class Main{

    private static final String TAG = "Camera";
    public static int[] findClosestFpsRange(Camera camera,
            int minFrameRate, int maxFrameRate) {
        minFrameRate *= 1000;//from w  w w  .  j  a  va 2 s .co  m
        maxFrameRate *= 1000;
        Camera.Parameters parameters = camera.getParameters();
        int minIndex = 0;
        int minDiff = Integer.MAX_VALUE;
        List<int[]> rangeList = parameters.getSupportedPreviewFpsRange();
        Log.d(TAG, "support preview fps range list: "
                + dumpFpsRangeList(rangeList));
        for (int i = 0; i < rangeList.size(); i++) {
            int[] fpsRange = rangeList.get(i);
            if (fpsRange.length != 2) {
                continue;
            }
            int minFps = fpsRange[0] / 1000;
            int maxFps = fpsRange[1] / 1000;
            int diff = Math.abs(minFps - minFrameRate)
                    + Math.abs(maxFps - maxFrameRate);
            if (diff < minDiff) {
                minDiff = diff;
                minIndex = i;
            }
        }
        int[] result = rangeList.get(minIndex);
        return result;
    }
    private static String dumpFpsRangeList(List<int[]> rangeList) {
        String result = "";
        for (int[] range : rangeList) {
            if (range.length != 2) {
                continue;
            }
            result += "(" + range[0] + "," + range[1] + ") ";
        }
        return result;
    }

}

Related Tutorials