Android camera freezes after taking one photo

后端 未结 6 1434
我在风中等你
我在风中等你 2021-01-04 00:34

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

相关标签:
6条回答
  • 2021-01-04 01:11

    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.

    0 讨论(0)
  • 2021-01-04 01:11

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

    0 讨论(0)
  • 2021-01-04 01:13

    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();}
    
    0 讨论(0)
  • 2021-01-04 01:16

    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

    0 讨论(0)
  • 2021-01-04 01:16

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

    0 讨论(0)
  • 2021-01-04 01:25

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

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

    it would work fine.

    0 讨论(0)
提交回复
热议问题