Advertisement
Guest User

Untitled

a guest
May 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. preview.setOnPreviewOutputUpdateListener { previewOutput ->
  2. cameraTextureView.surfaceTexture = previewOutput.surfaceTexture
  3.  
  4. // Compute the center of preview (TextureView)
  5. val centerX = cameraTextureView.width.toFloat() / 2
  6. val centerY = cameraTextureView.height.toFloat() / 2
  7.  
  8. // Correct preview output to account for display rotation
  9. val rotationDegrees = when (cameraTextureView.display.rotation) {
  10. Surface.ROTATION_0 -> 0
  11. Surface.ROTATION_90 -> 90
  12. Surface.ROTATION_180 -> 180
  13. Surface.ROTATION_270 -> 270
  14. else -> return@setOnPreviewOutputUpdateListener
  15. }
  16.  
  17. val matrix = Matrix()
  18. matrix.postRotate(-rotationDegrees.toFloat(), centerX, centerY)
  19.  
  20. // Finally, apply transformations to TextureView
  21. cameraTextureView.setTransform(matrix)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement