Skip to content

Instantly share code, notes, and snippets.

@traendy
Created March 29, 2019 18:01
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/fc4ec625a0190449f039ebf2f820ae66 to your computer and use it in GitHub Desktop.
Save traendy/fc4ec625a0190449f039ebf2f820ae66 to your computer and use it in GitHub Desktop.
Calls rotation depending on ExifInterface.
private fun rotateImageIfRequired(img: Bitmap, selectedImage: Uri): Bitmap? {
selectedImage.path?.let {
val orientation = ExifInterface(it).getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL)
return when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> rotateImage(img, 90f)
ExifInterface.ORIENTATION_ROTATE_180 -> rotateImage(img, 180f)
ExifInterface.ORIENTATION_ROTATE_270 -> rotateImage(img, 270f)
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> flip(img, true)
ExifInterface.ORIENTATION_FLIP_VERTICAL -> flip(img, false)
else -> img
}
}
return img
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment