Why is there a preview of the taken image shown after I take a picture with the camera on Android?

StackOverflow https://stackoverflow.com/questions/21991704

Вопрос

when I make a call to mCamera.takePicture(null, null, null, null); (for simplicity I have omitted the callbacks) the preview freezes and shows a preview of the scene that was just captured. Why is that the case. Can I somehow control this behaviour? And, what does actually happen? Is there a new view that gets attached or does my camera preview simple stop?

Это было полезно?

Решение

What does actually happen? Is there a new view that gets attached or does my camera preview simply stop?

No new view gets attached by default. The preview just stops. The documentation for Camera states this clearly:

Preview will be stopped after the image is taken; callers must call startPreview() again if they want to re-start preview or take more pictures.

It also goes on to say:

After calling this method, you must not call startPreview() or take another picture until the JPEG callback has returned.

So, the best place to call startPreview() again would be the JPEG callback. Any time before that, the camera hardware is still processing the previous image, and wouldn't be able to give you a preview. That's the main reason that it "freezes"; the camera hardware is just busy.

It's also a visual cue to the user that:

  • a picture was taken
  • the picture looks like "this"

That's icing on the cake, but even if you didn't care about that, it would still do it.

Can I somehow control this behaviour?

Through the publicly expose API? Definitely not. You can restart the preview once the camera is done processing(as above), but you can't prevent it from freeze-framing when you call takePicture().

Whether it's possible by going further into the camera firmware, I can't really say. However, since there are roughly a bazillion different cameras used in Android devices, this would likely be an exercise in futility if you weren't working on one specific device.

Even with one specific device, I can't see how you'd overcome it altogether. At a bare minimum, the camera will be busy processing the image for some amount of time. Even high-end DSLR cameras that I've seen freeze the preview at least for the duration of the exposure.

Другие советы

After calling takePicture() you can hide the preview surface under another view (e.g. ImageView). If you use OpenGL to render the preview texture instead of SurfaceView, you have even more tricks in your sleeve.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top