get Camera Pixels - Android android.hardware

Android examples for android.hardware:Camera Size

Description

get Camera Pixels

Demo Code

import java.util.List;

import android.hardware.Camera;
import android.hardware.Camera.Size;

public class Main {

  public static String getCameraPixels(int paramInt) {
    if (paramInt == 2)
      return "??";
    Camera localCamera = Camera.open(paramInt);
    Camera.Parameters localParameters = localCamera.getParameters();
    localParameters.set("camera-id", 1);
    List<Size> localList = localParameters.getSupportedPictureSizes();
    if (localList != null) {
      int heights[] = new int[localList.size()];
      int widths[] = new int[localList.size()];
      for (int i = 0; i < localList.size(); i++) {
        Size size = (Size) localList.get(i);
        int sizehieght = size.height;
        int sizewidth = size.width;
        heights[i] = sizehieght;// w w  w  .j a  va2 s.c  o m
        widths[i] = sizewidth;
      }
      int pixels = getMaxNumber(heights) * getMaxNumber(widths);
      localCamera.release();
      return String.valueOf(pixels / 10000) + " ??";

    } else
      return "??";

  }

  public static int getMaxNumber(int[] paramArray) {
    int temp = paramArray[0];
    for (int i = 0; i < paramArray.length; i++) {
      if (temp < paramArray[i]) {
        temp = paramArray[i];
      }
    }
    return temp;
  }

}

Related Tutorials