Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun rotateBitmap(bitmap: Bitmap, orientation: Int): Bitmap? {
- val matrix = Matrix()
- when (orientation) {
- ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> matrix.setScale(-1F, 1F)
- ExifInterface.ORIENTATION_ROTATE_180 -> matrix.setRotate(180F)
- ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
- matrix.setRotate(180F)
- matrix.postScale(-1F, 1F)
- }
- ExifInterface.ORIENTATION_TRANSPOSE -> {
- matrix.setRotate(90F)
- matrix.postScale(-1F, 1F)
- }
- ExifInterface.ORIENTATION_ROTATE_90 -> {
- matrix.setRotate(90F)
- }
- ExifInterface.ORIENTATION_TRANSVERSE -> {
- matrix.setRotate(-90F)
- matrix.postScale(-1F, 1F)
- }
- ExifInterface.ORIENTATION_ROTATE_270 -> {
- matrix.setRotate(-90F)
- }
- else -> return bitmap
- }
- return try {
- val rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
- bitmap.recycle()
- rotatedBitmap
- } catch (e: Exception) {
- null
- }
- }
Add Comment
Please, Sign In to add comment