aru*_*_10 6 camera android kotlin android-camerax
基本上,我的相机应用程序设置为肖像模式。但是,用户可以通过相应旋转手机来拍摄肖像或风景照片(应用程序不旋转)。
所以我的问题是,我们如何找到捕获的图像方向?
我尝试使用DisplayManager.DisplayListener,但是,它仅在应用程序方向发生时才有效。由于我已阻止应用程序的方向为纵向模式,因此它在这里不会得到任何回调。
我什至尝试使用ExifInterface,但是,它总是给出 6 作为旋转。
我正在寻找使用 CameraX api 的解决方案。
我也有这个问题。解决这个问题的方法是使用设备传感器数据获得正确的方向,然后将其设置在我的imageCapture对象中。请参阅下面的片段。
orientationEventListener = object : OrientationEventListener(context) {
override fun onOrientationChanged(orientation: Int) {
// Monitors orientation values to determine the target rotation value
val rotation = if (orientation >= 45 && orientation < 135) {
Surface.ROTATION_270
} else if (orientation >= 135 && orientation < 225) {
Surface.ROTATION_180
} else if (orientation >= 225 && orientation < 315) {
Surface.ROTATION_90
} else {
Surface.ROTATION_0
}
imageCapture?.setTargetRotation(rotation)
}
}
Run Code Online (Sandbox Code Playgroud)
这也是 Google 问题跟踪器中类似问题的推荐方法: https: //issuetracker.google.com/issues/144944155
| 归档时间: |
|
| 查看次数: |
2511 次 |
| 最近记录: |