Android Camera Orientation Check getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath)

Here you can find the source of getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath)

Description

Gets the camera photo orientation.

License

Open Source License

Parameter

Parameter Description
context the context
imageUri the image uri
imagePath the image path

Exception

Parameter Description
IOException Signals that an I/O exception has occurred.

Return

the camera photo orientation

Declaration

public static int getCameraPhotoOrientation(Context context,
        Uri imageUri, String imagePath) throws IOException 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.IOException;
import android.content.Context;

import android.media.ExifInterface;
import android.net.Uri;

public class Main {
    /**//from   www.  j av a 2s.c  o m
     * Gets the camera photo orientation.
     * 
     * @param context
     *            the context
     * @param imageUri
     *            the image uri
     * @param imagePath
     *            the image path
     * @return the camera photo orientation
     * @throws IOException
     *             Signals that an I/O exception has occurred.
     */
    public static int getCameraPhotoOrientation(Context context,
            Uri imageUri, String imagePath) throws IOException {
        int rotate = 0;
        context.getContentResolver().notifyChange(imageUri, null);
        File imageFile = new File(imagePath);

        ExifInterface exif = new android.media.ExifInterface(
                imageFile.getAbsolutePath());
        int orientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotate = 270;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotate = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotate = 90;
            break;
        }
        return rotate;
    }
}

Related

  1. getCameraOrientation(int cameraId)
  2. getDisplayOrientation(int degrees, int cameraId)
  3. getCameraDisplayOrientation(Context context, int cameraId, android.hardware.Camera camera)