首页 > 解决方案 > Android Studio 上的自动对焦

问题描述

我在 android studio 工作并使用 kotlin,我试图让相机在我的应用程序中自动对焦。

这里有一个类似的问题:https ://stackoverflow.com/a/34528716/6939854

我正在寻找一种方法来实现与 androidx 类似的东西。

我的一些代码也是:

 private fun startCamera() {
        val previewConfig = PreviewConfig.Builder().apply {
            setTargetAspectRatio(Rational(1, 1))
            setTargetResolution(Size(1000, 1000))
        }.build()

        // Build the viewfinder use case

        val preview = Preview(previewConfig)

        // Every time the viewfinder is updated, recompute layout
        preview.setOnPreviewOutputUpdateListener {

            // To update the SurfaceTexture, we have to remove it and re-add it
            val parent = viewFinder.parent as ViewGroup
            parent.removeView(viewFinder)
            parent.addView(viewFinder, 0)

        viewFinder.surfaceTexture = it.surfaceTexture
        updateTransform()
        }
    CameraX.bindToLifecycle(this as LifecycleOwner,preview)
}

标签: androidkotlinautofocusandroid-camerax

解决方案


推荐阅读