What's the best way to call StartPreview() after an image is captured?

后端 未结 2 1679
抹茶落季
抹茶落季 2020-12-25 08:21

Once a call is made to Camera.takePicture(), my preview will stop updating as described in the docs. What\'s the best way to detect that the image capture process is finishe

2条回答
  •  情深已故
    2020-12-25 08:41

    Since the PictureCallback is started in a separate thread anyway (it will not lock the UI), you don't need to use an AsyncTask to call the capture.

    There are two ways to do what you want to do, the easiest is the following:

    mCamera.startPreview(); //preview has to be started before you can take a picture
    mCamera.takePicture(null, null, mPictureCallback); //take a picture
    
    private PictureCallback mPictureCallback = new PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            camera.startPreview(); //once your camera has successfully finished
                                   //its capture it's safe to restart the preview
            ... //anything else you want to do to process that image
        }
    }
    

    The second would be using an anonymous function, e.g.:

    mCamera.takePicture(null, null, new PictureCallback(){
        ...
    });
    

    Both have their uses, depending on your needs.

提交回复
热议问题