For still image capture, we need to get the right fps range such that the camera can slow down the framerate to allow for less-noisy/dark viewfinder output in dark conditions. - Android Camera

Android examples for Camera:Camera Attribute

Description

For still image capture, we need to get the right fps range such that the camera can slow down the framerate to allow for less-noisy/dark viewfinder output in dark conditions.

Demo Code

/*/*from ww  w .jav  a2  s.  co  m*/
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import java.util.List;

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

public class Main {
  private static final String TAG = "Util";
  private final static int MAX_PREVIEW_FPS_TIMES_1000 = 400000;
  private final static int PREFERRED_PREVIEW_FPS_TIMES_1000 = 30000;

  /**
   * For still image capture, we need to get the right fps range such that the
   * camera can slow down the framerate to allow for less-noisy/dark viewfinder
   * output in dark conditions.
   *
   * @param params
   *          Camera's parameters.
   * @return null if no appropiate fps range can't be found. Otherwise, return the
   *         right range.
   */
  public static int[] getPhotoPreviewFpsRange(Parameters params) {
    return getPhotoPreviewFpsRange(params.getSupportedPreviewFpsRange());
  }

  public static int[] getPhotoPreviewFpsRange(List<int[]> frameRates) {
    if (frameRates.size() == 0) {
      Log.e(TAG, "No suppoted frame rates returned!");
      return null;
    }

    // Find the lowest min rate in supported ranges who can cover 30fps.
    int lowestMinRate = MAX_PREVIEW_FPS_TIMES_1000;
    for (int[] rate : frameRates) {
      int minFps = rate[Parameters.PREVIEW_FPS_MIN_INDEX];
      int maxFps = rate[Parameters.PREVIEW_FPS_MAX_INDEX];
      if (maxFps >= PREFERRED_PREVIEW_FPS_TIMES_1000 && minFps <= PREFERRED_PREVIEW_FPS_TIMES_1000
          && minFps < lowestMinRate) {
        lowestMinRate = minFps;
      }
    }

    // Find all the modes with the lowest min rate found above, the pick the
    // one with highest max rate.
    int resultIndex = -1;
    int highestMaxRate = 0;
    for (int i = 0; i < frameRates.size(); i++) {
      int[] rate = frameRates.get(i);
      int minFps = rate[Parameters.PREVIEW_FPS_MIN_INDEX];
      int maxFps = rate[Parameters.PREVIEW_FPS_MAX_INDEX];
      if (minFps == lowestMinRate && highestMaxRate < maxFps) {
        highestMaxRate = maxFps;
        resultIndex = i;
      }
    }

    if (resultIndex >= 0) {
      return frameRates.get(resultIndex);
    }
    Log.e(TAG, "Can't find an appropiate frame rate range!");
    return null;
  }
}

Related Tutorials