I am doing some image processing of previews captured by the camera. It is cpu consuming task and I have to stop preview to make it faster. Before new frame is being processed I am calling Camera.stopPreview() and after Camera.startPreview().
However, I would like to have last captured frame displayed on SurfaceView after stopping the preview. It works ‘out of the box’ on 2.3 devices, however, SurfaceView gets black after calling Camera.stopPreview() on older versions of SDK. Does anyone know what has changed and what to do?
Yes, this was an improvement of the 2.3.
I had this problem in 2.2 as well, there was no way to work on a preview image despite the fact this was theoretically possible according to the API. To solve this I had to actually take a picture using
Camera.takePicture(null, null, Camera.PictureCallback myCallback)(see info here) and then to implement a callback to handle the taken picture. The instance of the class that implements this callback is actually the parameter to pass toCamera.takePicture()and the callback method itself looks like this:Doing that way prevents the picture to be saved on the external storage with the regular pictures taken with the camera application. Should you need to serialize the
Bitmapyou’ll have to do it explicitely. But it doesn’t prevent the camera’s trigger sound from being emitted.Camera.takePicture()has to be called wile the preview is running.stopPreview()can be called right after.One thing to be careful with /!\:
Camera.takePicture()is not reentrant (at all). The callback must have returned before any subsequent call ofCamera.takePicture(). This was freezing my phone, I had to shutdown and restart it before it to be usable again. As the action was triggered by a button, on my side, I had to shield it with a boolean: