没有找到任何将 Camera2Config 或 Camera2Config.Extender 设置为 CameraX 的示例。
您能否提供一个将这些对象设置为 CameraX 的示例,以便获得回调方法调用等。
基本上我想以 androidx.camera.camera2.impl.Camera.State 的格式获取相机的状态。
最佳答案
我最近也需要这个,在撰写本文时,这是对我有用的方式。 请注意,这种方式可能会停止工作,因为 CameraX 处于 alpha 状态。
基本上,您需要一个 Config.ExtendableBuilder
并将其传递给 Camera2Config.Extender
的构造函数 before 您调用 build ()
并创建 UseCase。
例如,我从 CameraX sample 中获取了代码并将其调整为使用 Camera2Config.Extender
。
// Set up the view finder use case to display camera preview
val viewFinderConfigBuilder = PreviewConfig.Builder().apply {
setLensFacing(lensFacing)
// We request aspect ratio but no resolution to let CameraX optimize our use cases
setTargetAspectRatio(screenAspectRatio)
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
setTargetRotation(viewFinder.display.rotation)
}
// Create the extender and pass in the config builder we want to extend
val previewExtender = Camera2Config.Extender(viewFinderConfigBuilder)
// Listen to camera state changes
previewExtender.setDeviceStateCallback(object : CameraDevice.StateCallback() {
// implementation omitted for sake of simplicity
})
// Build your config as usual and create your wanted UseCase with it
val viewFinderConfig = viewFinderConfigBuilder.build()
// Use the auto-fit preview builder to automatically handle size and orientation changes
preview = AutoFitPreviewBuilder.build(viewFinderConfig, viewFinder)
此外,我建议不要使用任何实现细节,而是使用 CameraDevice.StateCallback
,如上例所示。
关于android - 如何在 CameraX 中使用 Camera2Config.Extender,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57110139/