[英]Android CameraX - manually change exposure compensation?
I'm using CameraX for my project.我在我的项目中使用 CameraX。 I have created preview useCase and capture useCase.我创建了预览用例并捕获用例。
final CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(lensFacing).build();
previewBuilder = new Preview.Builder()
.setTargetResolution(targetOutputSize)
.setTargetRotation(rotation);
preview = previewBuilder.build();
final ImageCapture.Builder imageCaptureBuilder = new ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setTargetResolution(targetOutputSize)
.setTargetRotation(rotation);
imageCapture = imageCaptureBuilder.build();
Everything works fine.一切正常。 Now, I need to add functionality to manually change exposure compensation, but I can't find any reference in official documentation or anywhere else how to do this.现在,我需要添加手动更改曝光补偿的功能,但我在官方文档或其他任何地方找不到任何参考资料。 Is it possible with CameraX, or I need to switch to Camera2 API?是否可以使用 CameraX,或者我需要切换到 Camera2 API?
Please, any help is welcome.请,欢迎任何帮助。
Looks like there is a Camera2Interop
class under the CameraX API which allows you to internally change the values.看起来 CameraX API 下有一个Camera2Interop
类,它允许您在内部更改值。 This is the official documentation: Camera2Interop.Extender这是官方文档: Camera2Interop.Extender
Before building your ImageCapture, add this:在构建 ImageCapture 之前,添加以下内容:
Camera2Interop.Extender(imageCaptureBuilder)
.setCaptureRequestOption(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, value);
There is new version of CameraX library.有新版本的 CameraX 库。
def camerax_version = '1.0.0-beta09'
Firstly add those dependencies to gradle file.首先将这些依赖项添加到 gradle 文件中。
// CameraX core library
implementation "androidx.camera:camera-core:$camerax_version"
// CameraX Camera2 extensions
implementation "androidx.camera:camera-camera2:$camerax_version"
This version supports Exposure compensation which can be adjusted in runtime.此版本支持可在运行时调整的曝光补偿。 First create preview and takePicure use cases, and then bind those use cases to cameraProvider.首先创建 preview 和 takePicure 用例,然后将这些用例绑定到 cameraProvider。
camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture);
Now we have camera instance and it can be used to retrive CameraInfo, and from CameraInfo, we retrive ExposureState.现在我们有了相机实例,它可用于检索 CameraInfo,并且从 CameraInfo 检索 ExposureState。
ExposureState exposureState = camera.getCameraInfo().getExposureState();
We can use exposureState to check if exposure compensation is supported on device我们可以使用 ExposureState 来检查设备是否支持曝光补偿
if (!exposureState.isExposureCompensationSupported()) return;
Next we need to get ExposureCompensation Range接下来我们需要得到 ExposureCompensation Range
Range<Integer> range = exposureState.getExposureCompensationRange();
Finally, we can set ExposureCompensation index in following way最后,我们可以通过以下方式设置 ExposureCompensation 指数
if (range.contains(index))
camera.getCameraControl().setExposureCompensationIndex(index);
In case you want to know when the camera completed changing the exposure settings, do something like (camerax_version = '1.0.0'):如果您想知道相机何时完成更改曝光设置,请执行以下操作(camerax_version = '1.0.0'):
lateinit var myCameraExposureListener: ListenableFuture<Int>
and then进而
myCameraExposureListener =
myCameraControl!!.setExposureCompensationIndex(exposureCompensationIndex);
myCameraExposureListener.addListener({
try {
Log.v(TAG, "Changing Exposure Settings Completed")
} catch (exception: Exception) {
Log.v(TAG, "Changing Exposure Settings Failed")
}
}, ContextCompat.getMainExecutor(context) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.