Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Matrix; import android.media.ExifInterface; import android.util.Log; public class Main { public static final String TAG = "AirImagePicker"; static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) { Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath"); try { // Get orientation from EXIF ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); // Compute rotation matrix Matrix rotation = new Matrix(); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotation.preRotate(90); break; case ExifInterface.ORIENTATION_ROTATE_180: rotation.preRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_270: rotation.preRotate(270); break; } // Return new bitmap Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotation, true); } catch (Exception exception) { Log.d(TAG, "Couldn't fix bitmap orientation: " + exception.getMessage()); Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return bitmap; } } }