Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.IOException;

import android.media.ExifInterface;

public class Main {
    /**
     * <pre>
     * Get rotation angle of an image.
     * This information is stored in image file. Therefore, this method needs path to file, not a {@link Bitmap} object or byte array.
     * </pre>
     * @param imagePath absolute path to image file
     * @return one of 0, 90, 180, 270
     */
    public static int getImageRotateAngle(String imagePath) throws IOException {
        ExifInterface exif = new ExifInterface(imagePath);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int angle = 0;
        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            angle = 90;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            angle = 180;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            angle = 270;
        }

        return angle;
    }
}