コード例 #1
0
  private void releaseCameraAndPreview() {
    if (mCamera != null) {
      mCamera.stopPreview();
      mCamera.release();
      mCamera = null;
    }

    if (mPreview != null) {
      mPreview.destroyDrawingCache();
      mPreview.setCamera(null);
    }
  }
コード例 #2
0
  private boolean safeCameraOpenInView(View view) {
    boolean qOpened = false;
    releaseCameraAndPreview();
    mCamera = getCameraInstance();
    setCameraDisplayOrientation(getActivity(), Camera.CameraInfo.CAMERA_FACING_BACK, mCamera);
    qOpened = (mCamera != null);

    if (qOpened == true) {
      mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
      FrameLayout preview = (FrameLayout) view.findViewById(R.id.camera_preview);
      preview.addView(mPreview);
      mPreview.startCameraPreview();
    }
    return qOpened;
  }