【问题标题】:How to show camera focus rectangle with Android CameraX如何使用 Android CameraX 显示相机焦点矩形
【发布时间】:2022-01-12 19:55:15
【问题描述】:

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

focus-on-tap 的实现方式如下: 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;
                }
            });

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

有什么想法吗?

【问题讨论】:

    标签: android android-camera android-camerax


    【解决方案1】:

    使用 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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      相关资源
      最近更新 更多