Example usage for android.hardware Camera release

List of usage examples for android.hardware Camera release

Introduction

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

Prototype

public final void release() 

Source Link

Document

Disconnects and releases the Camera object resources.

Usage

From source file:Main.java

public static void releaseCamera(Camera camera) {
    camera.release();
}

From source file:Main.java

public static void releaseCamera(Camera camera) {
    if (camera != null) {
        camera.release(); // release the camera for other applications
        camera = null;/*  ww w . j a  va  2s. c  o m*/
    }
}

From source file:Main.java

public static void close(Context context) {
    Camera cam = Camera.open();
    cam.stopPreview();
    cam.release();

}

From source file:Main.java

public static boolean isBackCameraAvailable() {
    try {// w  w w  .  j  ava2  s. c o m
        Camera camera = Camera.open();
        if (null != camera) {
            camera.release();
            camera = null;
            return true;
        }
    } catch (Exception e) {
    }
    return false;
}

From source file:Main.java

public static Camera releaseCamera(Camera camera) {
    if (camera != null) {
        camera.stopPreview();//w ww  .  j  a  va2  s  .co m
        camera.release();
        camera = null;
    }
    return camera;
}

From source file:Main.java

public static int getCameraFirstId(Context ctx) {

    if (sCameraFirstIndex != -1)
        return sCameraFirstIndex;

    Camera camera = null;

    try {/*w  ww. ja  va2 s. c  om*/
        camera = Camera.open(0);
        sCameraFirstIndex = 0;
        camera.release();
        camera = null;

    } catch (Exception ex) {
        sCameraFirstIndex = 1;
    }

    return sCameraFirstIndex;
}

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

private static String getDeviceInfo() {
    try {/*from w  ww  . ja va  2 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

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 ww  w  .  ja va 2s  .  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

public static boolean closeFlightLight(Camera camera) {
    if (null != camera) {
        Parameters parameters = camera.getParameters();
        List<String> list = parameters.getSupportedFlashModes();
        for (String string : list) {
            if (Parameters.FLASH_MODE_OFF.equals(string)) {
                parameters.setFlashMode(string);
                camera.setParameters(parameters);
                camera.stopPreview();/* w  ww. ja v a 2 s. c o  m*/
                camera.release();
                camera = null;
                return true;
            }
        }
    }
    return false;
}

From source file:Main.java

/**
 * Checks if the device has a camera flash
 *
 * @param context the context/*from   w ww.  jav a2 s. com*/
 * @return true if camera flash is available
 */
public static boolean hasCameraFlash(@NonNull Context context, @NonNull Camera camera) {
    boolean hasFlash = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
    try {
        Camera.Parameters p;

        if (hasFlash) {
            p = camera.getParameters();
            if (p.getSupportedFlashModes() == null) {
                hasFlash = false;
            } else {
                if (p.getSupportedFlashModes().size() == 1 && p.getSupportedFlashModes().get(0).equals("off")) {
                    hasFlash = false;
                }
            }
        }
    } finally {
        camera.release();
    }
    return hasFlash;
}