我在自动对焦模式下使用 Pixel 8 Pro,当我非常接近物体时,它会将相机切换到微距模式。我怎样才能禁用它?
我尝试过:
setStereoCameraUsage(EnumSet.of(CameraConfig.StereoCameraUsage.DO_NOT_USE))
我希望相机保持广角状态
为了解决您的问题,您可以尝试更改两个选项,第一个是在代码相机中添加一些额外的更改,您可以在下面看到我的示例。
private fun setupCamera() {
try {
val cameraManager = getSystemService(Context.CAMERA_SERVICE) as CameraManager
val cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId)
// Create camera configuration
val cameraConfig = CameraConfig.Builder()
.apply {
// Disable stereo/macro features
setStereoCameraUsage(EnumSet.of(CameraConfig.StereoCameraUsage.DO_NOT_USE))
// Disable auto macro mode
setCaptureRequestOption(
CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
)
// Prevent automatic switching
setCaptureRequestOption(
CaptureRequest.CONTROL_EXTENDED_SCENE_MODE,
CaptureRequest.CONTROL_EXTENDED_SCENE_MODE_DISABLED
)
}
.build()
// Apply configuration
camera?.apply {
setConfiguration(cameraConfig)
} ?: throw IllegalStateException("Camera not initialized")
} catch (e: CameraAccessException) {
Log.e(TAG, "Failed to configure camera: ${e.message}")
} catch (e: IllegalArgumentException) {
Log.e(TAG, "Invalid camera configuration: ${e.message}")
}
}
不要忘记在 androidmanifest.xml 中添加权限
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
第二个是改为camerax,camerax可以让你轻松处理各种相机配置。 https://developer.android.com/media/camera/camerax