Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- preview.setOnPreviewOutputUpdateListener { previewOutput ->
- cameraTextureView.surfaceTexture = previewOutput.surfaceTexture
- // Compute the center of preview (TextureView)
- val centerX = cameraTextureView.width.toFloat() / 2
- val centerY = cameraTextureView.height.toFloat() / 2
- // Correct preview output to account for display rotation
- val rotationDegrees = when (cameraTextureView.display.rotation) {
- Surface.ROTATION_0 -> 0
- Surface.ROTATION_90 -> 90
- Surface.ROTATION_180 -> 180
- Surface.ROTATION_270 -> 270
- else -> return@setOnPreviewOutputUpdateListener
- }
- val matrix = Matrix()
- matrix.postRotate(-rotationDegrees.toFloat(), centerX, centerY)
- // Finally, apply transformations to TextureView
- cameraTextureView.setTransform(matrix)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement