get Optimal Video Size - Android android.media

Android examples for android.media:Video

Description

get Optimal Video Size

Demo Code

import java.util.List;

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

public class Main {

  private static final String TAG = "Camera";

  /**/*w ww.j a  va  2s  .  c  o  m*/
   * Iterate over supported video record sizes to pick the largest one which
   * satisfies maxAllowedWidth and maxAllowedHeight.
   *
   * @param sizes-
   *          Supported video record sizes.
   * @param maxAllowedWidth
   * @param maxAllowedHeight
   * @return Largest Video Record size with its dimension satisfying the specified
   *         max width and height
   */
  public static Camera.Size getOptimalVideoSize(List<Camera.Size> sizes, int maxAllowedWidth, int maxAllowedHeight) {
    if (sizes == null)
      return null;

    Camera.Size optimalSize = null;
    int calcWidth = 0;
    int calcHeight = 0;

    for (Camera.Size size : sizes) {
      Log.d(TAG, "SupportedSize(W, H) -> " + "(" + size.width + "," + size.height + ")");
      int width = size.width;
      int height = size.height;

      if (width <= maxAllowedWidth && height <= maxAllowedHeight) {
        if (width >= calcWidth && height >= calcHeight) {
          calcWidth = size.width;
          calcHeight = size.height;
          optimalSize = size;
        }
      }
    }

    return optimalSize;
  }

}

Related Tutorials