determine Bitmap Rotation - Android Graphics

Android examples for Graphics:Bitmap Rotate

Description

determine Bitmap Rotation

Demo Code


//package com.java2s;

import java.io.IOException;

import android.media.ExifInterface;

public class Main {
    /**//from  www  .  jav a  2 s  . c om
     * 
     * @param path the path to load the image from
     * @return returns the angle (in degrees) the Bitmap at <code>path</code> is rotated in, from the EXIF tag
     * @throws IOException when the file is not readable
     */
    public static int determineRotation(String path) throws IOException {
        // Some Samsung phones store orientation info in the Exif tags, if this
        // is the case, apply it here.
        ExifInterface exif = new ExifInterface(path);
        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;
        }
    }
}

Related Tutorials