我已经在我的应用程序中集成了cameraX,并且在清单文件中将方向设置为横向,但是预览始终显示方向肖像。如何设置默认横向的预览方向?
机器人:screenOrientation = “风景”
以上参数已设置为清单。
更改屏幕方向不会改变相机方向。
setOnPreviewOutputUpdateListener {
texture.surfaceTexture = it.surfaceTexture
updateTransform()
}
并调用上述方法以显示视图。
val matrix = Matrix()
val centerX = texture.width / 2f
val centerY = texture.height / 2f
val rotationDegrees = when (texture.display.rotation) {
Surface.ROTATION_0 -> 0
Surface.ROTATION_90 -> 90
Surface.ROTATION_180 -> 180
Surface.ROTATION_270 -> 270
else -> return
}
matrix.postRotate(-rotationDegrees.toFloat(), centerX, centerY)
texture.setTransform(matrix)
此纹理设置为TextureView。