Example usage for android.hardware Camera open

List of usage examples for android.hardware Camera open

Introduction

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

Prototype

public static Camera open(int cameraId) 

Source Link

Document

Creates a new Camera object to access a particular hardware camera.

Usage

From source file:Main.java

public static Camera openCamera(int index) {
    try {/* w  ww  . j  av  a2  s  .c o  m*/
        return Camera.open(index);
    } catch (RuntimeException e) {
        return null;
    }
}

From source file:Main.java

public static Camera getCamera(Integer id) {
    if (id == null)
        return null;
    return Camera.open(id);
}

From source file:Main.java

private static Camera openBackCamera() {
    return Camera.open(getCameraId(CameraInfo.CAMERA_FACING_BACK));
}

From source file:Main.java

private static Camera openFrontCamera() {
    return Camera.open(getCameraId(CameraInfo.CAMERA_FACING_FRONT));
}

From source file:Main.java

private static void obtainCameraRatios() {
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        Camera camera = Camera.open(i);
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);//from w w  w  .  ja  v  a 2 s. c o  m
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            frontCameraRatio = camera.getParameters().getPreferredPreviewSizeForVideo();
        } else {
            backCameraRatio = camera.getParameters().getPreferredPreviewSizeForVideo();
        }
        camera.release();
    }
}

From source file:Main.java

/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return Camera.open(0); // This is the line the error occurs
    } else {/*from  w  w  w  . ja v a 2s .  c om*/
        return Camera.open();
    }
}

From source file:Main.java

private static Camera getFrontCamera() {
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(i, cameraInfo);

        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            return Camera.open(i);
        }/*  w w w . ja va2s.  c  om*/
    }

    return null;
}

From source file:Main.java

/**
 * @return front camera// ww w. j av  a2  s . co  m
 */
public static Camera getFrontCamera() {
    CameraInfo cameraInfo = new CameraInfo();
    int cameraCount = Camera.getNumberOfCameras();
    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            cameraId = i;
            return Camera.open(i);
        }
    }
    return null;
}

From source file:Main.java

/**
 * A safe way to get an instance of the Camera object.
 *//*from  w  w w.  ja v a2s .  c o m*/
public static Camera getCameraInstance(Context context, int CameraId) {
    Camera c = null;
    if (!checkCameraHardware(context)) {
        return c; // device has no camera
    }

    try {
        c = Camera.open(CameraId); // attempt to get a Camera instance
        Log.d(TAG, "open camera succeed");
    } catch (Exception e) {
        // Camera is not available (in use or does not exist)
        Log.d(TAG, "open camera failed");
    }
    return c; // returns null if camera is unavailable
}

From source file:Main.java

public static Camera getCameraInstance(int id) {
    if (id == 0)//from w  w w  .j a  v  a 2s  . co  m
        return Camera.open(HDMIRXID);
    else
        return Camera.open(USBCAMERAID);
}