Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.graphics.Matrix; import android.media.ExifInterface; import android.net.Uri; import java.io.File; public class Main { public static Matrix rotateImage(Context context, Uri imageUri, File f) { Matrix matrix = new Matrix(); try { if (imageUri != null) { context.getContentResolver().notifyChange(imageUri, null); } ExifInterface exif = new ExifInterface(f.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: matrix.postRotate(270); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.postRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.postRotate(90); break; } } catch (Exception e) { e.printStackTrace(); } return matrix; } }