Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

Android camera2 enable auto flashlight

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...