I\'m doing one project with camera and after taking one photo camera freezes and u have to finish the activity and recall it again to take another photo, how can I take phot
Do any image processing in a background AsyncTask
. This will allow your UI Activity to continue on and take another picture.
Edit: I cannot delete an accepted answer so please see stoefin's answer below. Calling camera.startPreview()
before taking the next photo works for him.
I found a solution for this: After taking a picture, preview display will have stopped. To take more photos, call camera.startPreview()
again first.
The camera.startpreview(); answer didn't work for my case but the code below solved that problem for me and hope it helps others too.I used a thread to delay closing and opening of the camera after a photo is captured by 500ms
private void start_camera() {
try {
camera = Camera.open();
// camera.lock();
} catch (RuntimeException e) {
Log.e(tag, "init_camera: " + e);
return;
}
Camera.Parameters param = camera.getParameters();
param = camera.getParameters();
Camera.Size size = param.getSupportedPreviewSizes().get(0);
param.setPreviewSize(size.width, size.height);
camera.setParameters(param);
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewRunning = true;
} catch (Exception e) {
Log.e(tag, "init_camera: " + e);
return;
}}
private void captureImage() {
camera.takePicture(shutterCallback,null,jpegCallback);
Thread restart_preview=new Thread(){public void run(){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
camera.release();
camera=null;
start_camera();
}};
restart_preview.start();}
Instead of using the activities defined by the existing camera app on your phone, you can write your own Activity that uses the Camera API directly to accomplish the functionality you describe. The Camera class is documented here: http://developer.android.com/reference/android/hardware/Camera.html
The camera is freezing, because you are not restarting the preview of the camera, so restart it by calling camera.startpreview()
after capturing image you should stop the preview and start it back again.
mCamera.stopPreview();
mCamera.startPreview();
it would work fine.