Example usage for android.hardware Camera getCameraInfo

List of usage examples for android.hardware Camera getCameraInfo

Introduction

In this page you can find the example usage for android.hardware Camera getCameraInfo.

Prototype

public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) 

Source Link

Document

Returns the information about a particular camera.

Usage

From source file:Main.java

/**
 *
 * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT
 *                 or Camera.CameraInfo.CAMERA_FACING_BACK.
 * @return the default camera on the device. Returns null if camera is not available.
 *///  w  ww. j a v  a2  s  .  c  o  m
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static Camera getDefaultCamera(int position) {
    // Find the total number of cameras available
    int mNumberOfCameras = Camera.getNumberOfCameras();

    Log.d(TAG, "getDefaultCamera number:" + mNumberOfCameras + " position:" + position);

    // Find the ID of the back-facing ("default") camera
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == position) {
            return Camera.open(i);

        }
    }

    return null;
}

From source file:ac.blitz.acme.video.VideoCaptureDeviceInfoAndroid.java

private static String getDeviceInfo() {
    try {/*  ww  w  .j ava2  s .  c  o  m*/
        JSONArray devices = new JSONArray();
        for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
            CameraInfo info = new CameraInfo();
            Camera.getCameraInfo(i, info);
            String uniqueName = deviceUniqueName(i, info);
            JSONObject cameraDict = new JSONObject();
            devices.put(cameraDict);
            List<Size> supportedSizes;
            List<int[]> supportedFpsRanges;
            try {
                Camera camera = Camera.open(i);
                Parameters parameters = camera.getParameters();
                supportedSizes = parameters.getSupportedPreviewSizes();
                supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
                camera.release();
                Log.d(TAG, uniqueName);
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to open " + uniqueName + ", skipping");
                continue;
            }
            JSONArray sizes = new JSONArray();
            for (Size supportedSize : supportedSizes) {
                JSONObject size = new JSONObject();
                size.put("width", supportedSize.width);
                size.put("height", supportedSize.height);
                sizes.put(size);
            }
            // Android SDK deals in integral "milliframes per second"
            // (i.e. fps*1000, instead of floating-point frames-per-second) so we
            // preserve that through the Java->C++->Java round-trip.
            int[] mfps = supportedFpsRanges.get(supportedFpsRanges.size() - 1);
            cameraDict.put("name", uniqueName);
            cameraDict.put("front_facing", isFrontFacing(info)).put("orientation", info.orientation)
                    .put("sizes", sizes).put("min_mfps", mfps[Parameters.PREVIEW_FPS_MIN_INDEX])
                    .put("max_mfps", mfps[Parameters.PREVIEW_FPS_MAX_INDEX]);
        }
        String ret = devices.toString(2);
        return ret;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

/**
 * Return the back facing camera id/*from  w  w  w  . j av a 2  s .c  om*/
 * @return id of the camera
 */
public static int getCameraInformationId() {
    int cameraId = -1;
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            cameraId = i;
            break;
        }
    }
    return cameraId;
}

From source file:com.actionbarsherlock.sample.hcgallery.CameraFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create a RelativeLayout container that will hold a SurfaceView,
    // and set it as the content of our activity.
    mPreview = new Preview(this.getActivity());

    // Find the total number of cameras available
    mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the default camera
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            mDefaultCameraId = i;// ww w  .j  ava2 s . c om
        }
    }
    setHasOptionsMenu(mNumberOfCameras > 1);
}

From source file:com.gosuncn.cu.module.permission.fragment.CameraPreviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Open an instance of the first camera and retrieve its info.
    mCamera = getCameraInstance(CAMERA_ID);
    Camera.CameraInfo cameraInfo = null;

    if (mCamera != null) {
        // Get camera info only if the camera is available
        cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(CAMERA_ID, cameraInfo);
    }//from  w w  w.jav  a 2  s .  c o  m

    View root = inflater.inflate(R.layout.fragment_camera, null);

    // Get the rotation of the screen to adjust the preview image accordingly.
    final int displayRotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();

    // Create the Preview view and set it as the content of this Activity.
    mPreview = new CameraPreview(getActivity(), mCamera, cameraInfo, displayRotation);
    FrameLayout preview = (FrameLayout) root.findViewById(R.id.camera_preview);
    preview.addView(mPreview);

    return root;
}

From source file:com.example.android.system.runtimepermissions.camera.CameraPreviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Open an instance of the first camera and retrieve its info.
    mCamera = getCameraInstance(CAMERA_ID);
    Camera.CameraInfo cameraInfo = null;

    if (mCamera != null) {
        // Get camera info only if the camera is available
        cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(CAMERA_ID, cameraInfo);
    }//  ww  w  . j  a  v  a2s . c o m

    if (mCamera == null || cameraInfo == null) {
        // Camera is not available, display error message
        Toast.makeText(getActivity(), "Camera is not available.", Toast.LENGTH_SHORT).show();
        return inflater.inflate(R.layout.fragment_camera_unavailable, null);
    }

    View root = inflater.inflate(R.layout.fragment_camera, null);

    // Get the rotation of the screen to adjust the preview image accordingly.
    final int displayRotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();

    // Create the Preview view and set it as the content of this Activity.
    mPreview = new CameraPreview(getActivity(), mCamera, cameraInfo, displayRotation);
    FrameLayout preview = (FrameLayout) root.findViewById(R.id.camera_preview);
    preview.addView(mPreview);

    return root;
}

From source file:cn.pjt.rxjava.camera.CameraPreviewFragment.java

private void initCamera() {
    mCamera = getCameraInstance(CAMERA_ID);
    Camera.CameraInfo cameraInfo = null;

    if (mCamera != null) {
        // Get camera info only if the camera is available
        cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(CAMERA_ID, cameraInfo);
    }//from  ww  w. j  a va  2 s.c om

    // Get the rotation of the screen to adjust the preview image accordingly.
    final int displayRotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();

    if (getView() == null) {
        return;
    }

    FrameLayout preview = (FrameLayout) getView().findViewById(R.id.camera_preview);
    preview.removeAllViews();

    if (mPreview == null) {
        // Create the Preview view and set it as the content of this Activity.
        mPreview = new CameraPreview(getActivity(), mCamera, cameraInfo, displayRotation);
    } else {
        mPreview.setCamera(mCamera, cameraInfo, displayRotation);
    }

    preview.addView(mPreview);
}

From source file:at.wada811.utils.CameraUtils.java

/**
 * ??//from  ww w. j  a  v a2  s .co m
 * 
 * @param nCameraId
 * @return
 */
public static CameraInfo getCameraInfo(int nCameraId) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(nCameraId, info);
    return info;
}

From source file:com.ezartech.ezar.flashlight.Flashlight.java

private void init(final CallbackContext callbackContext) {
    this.callbackContext = callbackContext;

    if (!PermissionHelper.hasPermission(this, permissions[0])) {
        PermissionHelper.requestPermission(this, CAMERA_SEC, Manifest.permission.CAMERA);
        return;//from w w  w  . ja  va  2s.c  om
    }

    JSONObject jsonResult = new JSONObject();

    try {
        jsonResult.put("back", false);

        int mNumberOfCameras = Camera.getNumberOfCameras();

        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        for (int id = 0; id < mNumberOfCameras; id++) {
            Camera.getCameraInfo(id, cameraInfo);

            if (cameraInfo.facing != CameraInfo.CAMERA_FACING_BACK) {
                continue;
            }

            Parameters parameters;
            Camera camera = null;
            Camera releasableCamera = null;
            try {

                try {
                    if (id != voCameraId) {
                        camera = Camera.open(id);
                    } else {
                        camera = voCamera;
                    }

                } catch (RuntimeException re) {
                    System.out.println("Failed to open CAMERA: " + id);
                    continue;
                }

                parameters = camera.getParameters();

                List<String> torchModes = parameters.getSupportedFlashModes();
                boolean hasLight = torchModes != null && torchModes.contains(Parameters.FLASH_MODE_TORCH);

                if (hasLight) {
                    String key = "back";
                    cameraId = id;
                    ;
                    jsonResult.put(key, true);
                }

                //determine if camera should be released
                if (id != voCameraId) {
                    releasableCamera = camera;
                }

            } finally {
                if (releasableCamera != null) {
                    releasableCamera.release();
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Can't set exception", e);
        callbackContext.error("Unable to access Camera for light information.");
        return;
    }

    callbackContext.success(jsonResult);
}

From source file:com.czh.testmpeg.videorecord.CameraActivity.java

/**
 * ??,-1/*  www.j a  v  a  2 s.c o  m*/
 *
 * @return cameraId
 */
private int findFrontFacingCamera() {
    int cameraId = -1;
    //??
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            cameraId = i;
            cameraFront = true;
            break;
        }
    }
    return cameraId;
}