android - 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)
}
解决方案
推荐阅读
- python - 如何实现碰撞检测?
- powershell - 为什么从 Powershell switch 语句中的变量进行奇怪的赋值?
- reactjs - React Native 如何在应用程序中保存图像?
- c - 构建 FreeRDP 并安装错误:字段“des3_ctx”的类型不完整
- linux - 恢复无限嵌套/递归的 tmux 会话?
- c++ - 读取文件到 istream 替换类变量
- java - LibGDX 浮动与相机位置导致黑线与平铺地图
- java - 检查下一个要保存的输入是否在这些范围内
- class - fortran中的多态性
- android - 在 Android 生命周期中我应该在哪里使用 getIntent()