繁体   English   中英

如何使用 Android CameraX 显示相机焦点矩形

[英]How to show camera focus rectangle with Android CameraX

我在我的应用程序中使用 android camerax。

水龙头的焦点是在这个答案中实现的: https://stackoverflow.com/a/60095886/978067

            cameraPreview.setOnTouchListener((view, event)  -> {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        return true;
                    case MotionEvent.ACTION_UP:
                        MeteringPoint point = cameraPreview.getMeteringPointFactory().createPoint(event.getX(), event.getY());
                        FocusMeteringAction action = new FocusMeteringAction.Builder(point).build();
                        camera.getCameraControl().startFocusAndMetering(action);

                        // HOW TO SHOW RECTANGLE SIGHT HERE? Thanx!

                        return true;
                    default:
                        return false;
                }
            });

但我需要在焦点周围显示矩形视线(如标准相机应用程序中)

有什么想法吗?

使用 CameraX,点击对焦是使用触摸点 - x、y 坐标完成的。 您可以将焦点矩形 x 和 y 设置为运动事件 x 和 y。 焦点矩形应该是您可以创建的自定义视图。

/** Represents the x coordinate of the tap event */
val x = motionEvent.x
/** Represents the y coordinate of the tap event */
val y = motionEvent.y
// Setting the focus rectangle view x coordinate as the motion event x coordinate
focusRectangleView.x = x
// Setting the focus rectangle view y coordinate as the motion event y coordinate
focusRectangleView.y = y

这是您可以显示点击发生的焦点矩形视图的方式,并且还可以在您想要显示或隐藏它时简单地更改视图可见性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM