Android camera freezes after taking one photo

烂漫一生 提交于 2019-11-30 17:18:27

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.

stoefln

I found a solution for this: After taking a picture, preview display will have stopped. To take more photos, call camera.startPreview() again first.

after capturing image you should stop the preview and start it back again.

mCamera.stopPreview();
mCamera.startPreview();

it would work fine.

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

sunny verma

The camera is freezing, because you are not restarting the preview of the camera, so restart it by calling camera.startpreview()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!