Search code examples
androidandroid-cameraandroid-imageandroid-5.0-lollipop

Android L - Take flash image with autofocus using Camera2 api


Following camera2basic guide on Android L preview page, I am able to capture normal images, i.e. without flash or using auto-focus mechanism (I rely on passive focus)

However, I would like to take a flash image. The documentation states before taking flash image, I should call android.control.aePrecaptureTrigger to determine correct exposure.

My question:

  • How can I call AE Precapture trigger, wait for it to complete and then take the image using capture(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)?

Method I've already tried:

  • After user clicks capture image button, I start a preview
  • Set CONTROL_AE_PRECAPTURE_TRIGGER to CONTROL_AE_PRECAPTURE_TRIGGER_START
  • Monitor AE_STATE result in CaptureListener's onCaptureCompleted method
  • When AE_STATE converges, I set AE lock and take image using capture() method

However, the flash image is still over-exposed and sometimes, I get complete garbage image.

Has anyone able to get this working?

Once this is working, auto-focus mechanism can be used in similar fashion.

Thanks


Solution

  • Thanks for trying out the new camera2 API!

    You shouldn't need to lock AE; once you see AE_STATE as CONVERGED (or FLASH_REQUIRED), submit the still capture request.

    Things to verify:

    • Is your AE_MODE either ON_AUTO_FLASH or ON_ALWAYS_FLASH for both the preview and the still capture requests? If not, the metering routines won't be controlling flash power or firing correctly. The still capture and preview templates may just have AE mode set to ON, which means the flash won't be fired under AE control.
    • Are you using CAPTURE_INTENT_STILL_PICTURE for the still capture? If not, the flash won't be fired by the automatics. This is automatically set for TEMPLATE_STILL_CAPTURE.

    If you're seeing garbage images, please feel free to file a bug on our Android AOSP tracker: http://b.android.com

    Detailing the set of outputs you have for your session would be especially helpful, since we know there are some current bugs for certain output Surface sets.