0

I have set up a FrameLayout to be the preview screen for my camera and it works great.

private void fireUpCamera() {
    mCamera = getCameraInstance();  // Create an instance of Camera
    // Create our Preview view and set it as the content of our activity.
    mPreview = new CameraPreview(this, mCamera);// Create our Preview view.
    FrameLayout preview = (FrameLayout) findViewById(R.id.quest_image);
    preview.addView(mPreview);
}

how do I release this preview and camera in my cancel button without taking the picture?

Azkik
  • 75
  • 4
  • 13
  • What do you mean by "release"? Remove it? – Rawa Aug 13 '14 at 03:49
  • I want the frame to go blank again. calling fireUpCamera brings up the preview. My cancel button should stop the preview and camera. – Azkik Aug 13 '14 at 03:57

2 Answers2

2

Try the following function to make sure you have released the camera on cancel. You will need to reinitialise it with your fireUpCamera() method if you want to use it again.

protected void closeCameraAndPreview() {    
    if (mCamera != null) {
        mCamera .stopPreview();
        mCamera .setPreviewCallback(null);
        mPreview.getHolder().removeCallback(mPreview);
        mCamera .release();
        mCamera = null;
    }
    preview.removeView(mPreview);
}

I implemented it this way so that the camera was properly released rather than just hidden from sight.

CodeMonkey
  • 1,426
  • 1
  • 14
  • 32
0

If you want to remove the mPreview view from the FrameLayout named preview you could simply remove the view from the layout like this:

preview.removeView(mPreview);
Rawa
  • 13,357
  • 6
  • 39
  • 55