Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.media.ExifInterface;
import android.util.Log;
import java.io.IOException;

public class Main {
    private static final String TAG = "SDG [Bitmap Utils]";

    public static int getRotationAngle(String photoPath) {
        ExifInterface ei = null;
        try {
            ei = new ExifInterface(photoPath);
        } catch (IOException e) {
            Log.e(TAG, "Unexpected error occurred when getting rotation angle.");
        }
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            Log.d(TAG, "90 Degrees rotation needed");
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            Log.d(TAG, "180 Degrees rotation needed");
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            Log.d(TAG, "270 Degrees rotation needed");
            return 270;
        case ExifInterface.ORIENTATION_NORMAL:
        default:
            Log.d(TAG, "0 Degrees rotation needed");
            return 0;
        }
    }
}