Android在最近几个月发布了一个新的API camerax。我正在尝试了解如何让相机工作的自动对焦。
https://groups.google.com/a/android.com/forum/#!searchin/camerax-developers/auto$20focus|sort:date/camerax-developers/IQ3KZd8iOIY/LIbrRIqEBgAJ
这里有一个关于这个主题的讨论,但几乎没有关于它的具体文档。https://github.com/android/camera-samples/tree/master/CameraXBasic/app/src/main/java/com/android/example/cameraxbasic
这也是基本的camerax应用程序,但我找不到任何处理自动对焦的文件。
任何指向文档的提示或要点都是有帮助的。另外,我是android的新手,所以很可能我错过了一些让上面的链接更有用的东西。
发布于 2019-10-04 23:23:08
一些安卓设备存在一个问题,那就是相机不能通过CameraX自动对焦。CameraX团队已经意识到了这一点,并正在通过内部罚单对其进行跟踪,希望很快就能解决这个问题。
发布于 2020-11-19 02:54:51
只需指出,要让“点击聚焦”与PreviewView一起工作,您需要使用DisplayOrientedMeteringPointFactory。否则你会弄乱坐标。
val factory = DisplayOrientedMeteringPointFactory(activity.display, camera.cameraInfo, previewView.width.toFloat(), previewView.height.toFloat())对于其余部分,请使用MatPag的答案。
发布于 2019-10-03 16:45:37
你可以在这里找到关于焦点的文档,因为它是在"1.0.0-alpha05“中添加的。https://developer.android.com/jetpack/androidx/releases/camera#camera2-core-1.0.0-alpha05
基本上,你必须在你的视图上设置一个触摸监听器,然后抓住点击的位置
private boolean onTouchToFocus(View viewA, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_UP:
return focus(event);
break;
default:
// Unhandled event.
return false;
}
return true;
}
并将此位置转换为点
private boolean focus(MotionEvent event) {
final float x = (event != null) ? event.getX() : getView().getX() + getView().getWidth() / 2f;
final float y = (event != null) ? event.getY() : getView().getY() + getView().getHeight() / 2f;
TextureViewMeteringPointFactory pointFactory = new TextureViewMeteringPointFactory(textureView);
float afPointWidth = 1.0f / 6.0f; // 1/6 total area
float aePointWidth = afPointWidth * 1.5f;
MeteringPoint afPoint = pointFactory.createPoint(x, y, afPointWidth, 1.0f);
MeteringPoint aePoint = pointFactory.createPoint(x, y, aePointWidth, 1.0f);
try {
CameraX.getCameraControl(lensFacing).startFocusAndMetering(
FocusMeteringAction.Builder.from(afPoint, FocusMeteringAction.MeteringMode.AF_ONLY)
.addPoint(aePoint, FocusMeteringAction.MeteringMode.AE_ONLY)
.build());
} catch (CameraInfoUnavailableException e) {
Log.d(TAG, "cannot access camera", e);
}
return true;
}
https://stackoverflow.com/questions/58159891
复制相似问题