Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Matrix; import android.media.ExifInterface; public class Main { public static Bitmap rotateByExifInfo(Bitmap source, String path) { try { ExifInterface exifInterface = new ExifInterface(path); String tagName = ExifInterface.TAG_ORIENTATION; int defaultValue = ExifInterface.ORIENTATION_NORMAL; int orientation = exifInterface.getAttributeInt(tagName, defaultValue); switch (orientation) { case ExifInterface.ORIENTATION_NORMAL: return source; case ExifInterface.ORIENTATION_ROTATE_90: return rotate(source, 90); case ExifInterface.ORIENTATION_ROTATE_180: return rotate(source, 180); case ExifInterface.ORIENTATION_ROTATE_270: return rotate(source, 270f); default: return source; } } catch (Exception e) { return source; } } public static Bitmap rotate(Bitmap source, float degrees) { if (source == null || source.getWidth() == 0 || source.getHeight() == 0) return null; int width = source.getWidth(); int height = source.getHeight(); Matrix m = new Matrix(); float w = width; float h = height; float px = w / 2; float py = h / 2; m.setRotate(degrees, px, py); return Bitmap.createBitmap(source, 0, 0, width, height, m, true); } }