Java tutorial
//package com.java2s; //License from project: Apache License import android.media.ExifInterface; import java.io.IOException; public class Main { /** * Get the orientation rotate degree of an image file. * * @param soureFilePath * The file path of the image. * @return The orientation rotate degree of an image file(90 or 180 or 270). <br> * 0, if the image file has no orientation rotate degree or the * source file is not a valid image file. */ public static int getOrientationRotateDegree(String soureFilePath) { if (null == soureFilePath) { return 0; } try { ExifInterface exif = new ExifInterface(soureFilePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: { return 90; } case ExifInterface.ORIENTATION_ROTATE_180: { return 180; } case ExifInterface.ORIENTATION_ROTATE_270: { return 270; } default: { return 0; } } } catch (IOException e) { e.printStackTrace(); return 0; } } }