Android camera2 启用自动手电筒 [英] Android camera2 enable auto flashlight

查看:80
本文介绍了Android camera2 启用自动手电筒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在相机 2 中启用默认手电筒关闭或打开功能,我可以像默认相机一样启用其中的设置选项吗?

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.

推荐答案

您需要将相机的自动曝光模式设置为使用闪光灯的一种;通常是 AE_MODE_ON_AUTO_FLASHAE_MODE_ON_ALWAYS_FLASH.

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.

您可以通过查看设备上可用的模式AE_AVAILABLE_MODES.

然后您需要使用 AE 预捕获触发器 在进行主图像拍摄之前,可以进行预闪以进行准确的闪光亮度控制.

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. 确保您的预览请求具有所需的 AE 闪光模式,并将其设置为捕获会话的重复请求.
  2. 使用您的预览设置创建一个新的捕获请求构建器.
  3. 将该构建器的预捕获触发器设置为 START
  4. 使用该构建器创建一个请求,并使用它调用 CameraCaptureSession.capture()
  5. 等待 PRECAPTURE 的 AE_STATE出现和消失;在此期间,相机设备可能会点亮闪光灯以测量它需要的亮度.
  6. AE_STATE_PRECAPTURE 结束后,使用 STILL_CAPTURE 模板发出高分辨率捕获请求(将捕获意图控制设置为 STILL_CAPTURE,触发主闪光灯闪光).
  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).

Camera2Basic 示例包含所有用于闪存操作的内容,作为后续示例.如果设备支持,则使用 AE_MODE_AUTO_FLASH.

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.

这篇关于Android camera2 启用自动手电筒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆