alijandro
alijandro

Reputation: 12167

Android camera2 flash not fired in low light conditions in auto flash mode

I used camera2 to capture picture, and set the flash mode to auto. I set the request parameters as following.

CaptureRequest.Builder stillCaptureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
stillCaptureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

In the code above, the flash should be fired in low-light conditions. But it didn't work as expected. The flash didn't get fired in low-light conditions.

How can I set camera2 to auto flash mode?

Upvotes: 4

Views: 2057

Answers (2)

Ahmed Alghafli
Ahmed Alghafli

Reputation: 31

try this for auto flash

 // Use the same AE and AF modes as the preview.
            captureStillBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
            captureStillBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

Upvotes: 0

Francisco Durdin Garcia
Francisco Durdin Garcia

Reputation: 13357

Let's see if I can help you!

Try to set Flash_mode to OFF if you are using AE_MODE:

 builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
 builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);

and later update your preview setting again a repeatingRequest to your builder and callback:

mCaptureSession.setRepeatingRequest(builder.build(),
                    callback, backgroundHandler);

Also remember that if you want to check if everything is set correctly you can recover the state of your flash using result.get(CaptureResult.FLASH_STATE) from your captureCalback return value after or before take a picture.

In other way, don't forget to don't update the preview when the flash is being shoot or you will put off your flash before the photo as been shoot.

Upvotes: 1

Related Questions