Java tutorial
//package com.java2s; //License from project: Open Source License import android.media.ExifInterface; import java.io.File; import java.io.IOException; public class Main { /** * Extracts the EXIF rotation tag of an image file. * * @param filePath Path to the image file * @return Rotation in degrees * @throws IOException */ public static int getExifRotation(String filePath) throws IOException { ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; default: return 0; } } /** * Extracts the EXIF rotation tag of an image file. * * @param file The image file * @return Rotation in degrees * @throws IOException */ public static int getExifRotation(File file) throws IOException { return getExifRotation(file.getAbsolutePath()); } }