Skip to content

Instantly share code, notes, and snippets.

@deepak140596
Created August 28, 2019 13:52
Show Gist options
  • Save deepak140596/0d370a3deae87f0c23c1eecf1dec5e17 to your computer and use it in GitHub Desktop.
Save deepak140596/0d370a3deae87f0c23c1eecf1dec5e17 to your computer and use it in GitHub Desktop.
private fun updateTransform() {
val matrix = Matrix()
// Compute the center of the view finder
val centerX = viewFinder.width / 2f
val centerY = viewFinder.height / 2f
// Correct preview output to account for display rotation
val rotationDegrees = when(viewFinder.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)
// Finally, apply transformations to our TextureView
viewFinder.setTransform(matrix)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment