Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I enable default flashlight turn off or on feature in camera2, Can I enable settings options in it like default camera?

I seen some example like here and here but they are using their own buttons to turn on or off flash, here I want to use the default one by enabling it.

Any suggestions would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
237 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to set the camera's auto-exposure mode to one of the flash-using ones; generally that's either AE_MODE_ON_AUTO_FLASH or AE_MODE_ON_ALWAYS_FLASH.

You can check which modes are available on your device via AE_AVAILABLE_MODES.

Then you'll need to use the AE precapture trigger before doing the main image capture, so that a preflash can be fired for accurate flash brightness control.

  1. Ensure your preview request has the desired AE flash mode, have it set as the repeating request for your capture session.
  2. Create a new capture request builder with your preview settings.
  3. Set the precapture trigger to START for that builder
  4. Create one request with that builder, and call CameraCaptureSession.capture() with it
  5. Wait for the AE_STATE of PRECAPTURE to appear and disappear; during this time the camera device may light up the flash to measure how bright it needs to be.
  6. Once AE_STATE_PRECAPTURE ends, issue the high-resolution capture request using the STILL_CAPTURE template (which sets the capture intent control to STILL_CAPTURE, triggering the main flash firing).

The Camera2Basic sample includes all this for flash operation, as a sample to follow. It uses AE_MODE_AUTO_FLASH if supported by the device.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...