Java tutorial
//package com.java2s; import android.media.ExifInterface; import android.util.Log; public class Main { private static final String TAG = "TransformationUtils"; /** * Returns a matrix with rotation set based on Exif orientation tag. * If the orientation is undefined or 0 null is returned. * * @param pathToOriginal Path to original image file that may have exif data. * @return A rotation in degrees based on exif orientation */ public static int getOrientation(String pathToOriginal) { int degreesToRotate = 0; try { ExifInterface exif = new ExifInterface(pathToOriginal); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { degreesToRotate = 90; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { degreesToRotate = 180; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { degreesToRotate = 270; } } catch (Exception e) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Unable to get orientation for image with path=" + pathToOriginal, e); } } return degreesToRotate; } }