Skip to content

Instantly share code, notes, and snippets.

@traendy
Created March 29, 2019 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save traendy/4834b057870f527ab2022cb615265767 to your computer and use it in GitHub Desktop.
Save traendy/4834b057870f527ab2022cb615265767 to your computer and use it in GitHub Desktop.
Flips or rotates an Image.
private fun rotateImage(img: Bitmap, degree: Float): Bitmap {
val matrix = Matrix()
matrix.postRotate(degree)
return Bitmap.createBitmap(img, 0, 0, img.width, img.height, matrix, true)
}
private fun flip(bitmap: Bitmap, horizontal: Boolean): Bitmap {
val matrix = Matrix()
matrix.preScale((if (horizontal) -1f else 1f), (if (!horizontal) -1f else 1f))
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment