get Bitmap Orientation Degree - Android Graphics

Android examples for Graphics:Bitmap Orientation

Description

get Bitmap Orientation Degree

Demo Code


//package com.java2s;

import java.io.IOException;

import android.media.ExifInterface;

public class Main {

    public static int getBitmapDegree(String filepath) {
        int degree = 0;
        try {/*from  w ww  .  j a  v a2 s  .  c o m*/
            ExifInterface exifInterface = new ExifInterface(filepath);
            @SuppressWarnings("static-access")
            int orientation = exifInterface.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    exifInterface.ORIENTATION_NORMAL);
            switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
            default:
                break;
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return degree;
    }
}

Related Tutorials