get Rotate Degree From Exif - Android android.media

Android examples for android.media:ExifInterface

Description

get Rotate Degree From Exif

Demo Code


//package com.java2s;

import java.io.IOException;

import android.media.ExifInterface;

public class Main {
    static private int getRotateDegreeFromExif(String filePath) {
        int degree = 0;
        try {//from   w w w .j a  va2s.co  m
            ExifInterface exifInterface = new ExifInterface(filePath);
            int orientation = exifInterface.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_UNDEFINED);
            if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
                degree = 90;
            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
                degree = 180;
            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
                degree = 270;
            }
            if (degree != 0) {
                exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION,
                        "0");
                exifInterface.saveAttributes();
            }
        } catch (IOException e) {
            degree = -1;
            e.printStackTrace();
        }

        return degree;
    }
}

Related Tutorials