android - Camera X 的 AE 锁无法正常工作
问题描述
我使用 Camera X 并尝试使用 锁定 AF 和 AE FocusMeteringAction
,AF 锁定正常但 AE 没有锁定。可能是什么原因?
camerax_version = "1.1.0-alpha02"
val factory: MeteringPointFactory = previewView.meteringPointFactory
val point: MeteringPoint = factory.createPoint(x, y)
val builder = FocusMeteringAction.Builder(point)
builder.disableAutoCancel()
camerax?.cameraControl?.startFocusAndMetering(builder.build())
代码片段很简单,ListenableFuture
fromstartFocusAndMetering()
返回一个成功的结果,但是AE仍然是动态的并且没有被锁定。
我期待的结果:然后将应用程序指向明亮的东西(例如太阳或强光),然后锁定曝光。然后将相机远离光线,一切都会变得非常黑暗。这表明相机没有自动调整曝光(因为它被锁定)。
我的实际结果是:曝光调整,图片亮/正常。
将不胜感激任何想法!提前致谢!
解决方案
It's been a long time but this might be helpful to someone may ended up here.
I don't know if it is possible by using only CameraX apis. But I've achieved the expected behaviour with Camera2 apis. With the below snippet, the AF and AE can be measured and updated with a tap and stays locked afterwards until another tap occures.
private void initTapToFocus() {
previewView.setOnTouchListener((v, event) -> {
MeteringPointFactory meteringPointFactory = previewView.getMeteringPointFactory();
MeteringPoint point = meteringPointFactory.createPoint(event.getX(), event.getY());
FocusMeteringAction action = new FocusMeteringAction
.Builder(point, FocusMeteringAction.FLAG_AF)
.addPoint(point, FocusMeteringAction.FLAG_AE)
.disableAutoCancel()
.build();
//Unlock AE before the tap so it can be updated.
lockAe(false, () -> doFocusAndMetering(action));
return true;
});
}
private void doFocusAndMetering(FocusMeteringAction builder) {
ListenableFuture<FocusMeteringResult> future = cameraControl.startFocusAndMetering(builder);
//Lock AE again when measuring completed
future.addListener(() -> lockAe(true, () -> {}), executor);
}
private void lockAe(boolean lockAe, Runnable doWhenComplete) {
Camera2CameraControl camera2CameraControl = Camera2CameraControl.from(cameraControl);
CaptureRequestOptions options = new CaptureRequestOptions.Builder()
.setCaptureRequestOption(CaptureRequest.CONTROL_AE_LOCK, lockAe)
.build();
camera2CameraControl.setCaptureRequestOptions(options).addListener(doWhenComplete, executor);
}
推荐阅读
- ruby - 无法在 ruby 1.9.3 Alpine 上安装 ffi gem
- php - 您可以让 mailchimp 使用除订阅之外的其他词吗?
- linux - SMSC95xx 使用外部 PHY (TI DP83TC811):eth1 链路已关闭
- javascript - 如何使用选择框更改 div 的背景样式?
- sql - 如何使用您的管理员详细信息登录 psql
- python - 如果长度小于 3,子字符串不会输出任何内容
- c++ - 使用 CUDA 代码编译 MINPACK 库的问题
- python - 不使用烧瓶或 django 的 Python Twilio?
- html - GitHub Pages - 无法加载网页的 CSS
- excel - 如何正确计算excel中的百分比变化?