Android camera freezes after taking one photo

十年热恋 提交于 2019-12-18 19:01:44

问题


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 photo freeze for just 1-2 sec and then surface view to have the camera again. the same for video I am using media recorder, taking video press stop video saves and screen is still alive but I can not take video again I have to restart the activity?

Anybody have a solution?


回答1:


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.




回答2:


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




回答3:


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

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

it would work fine.




回答4:


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();}



回答5:


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




回答6:


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



来源:https://stackoverflow.com/questions/6139409/android-camera-freezes-after-taking-one-photo

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