Example usage for android.media ExifInterface getAttributeInt

List of usage examples for android.media ExifInterface getAttributeInt

Introduction

In this page you can find the example usage for android.media ExifInterface getAttributeInt.

Prototype

public int getAttributeInt(String tag, int defaultValue) 

Source Link

Document

Returns the integer value of the specified tag.

Usage

From source file:Main.java

static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) {
    Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath");
    try {/* w  ww .j  av a2s.  c om*/
        // Get orientation from EXIF
        ExifInterface exif = new ExifInterface(filePath);
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        // Compute rotation matrix
        Matrix rotation = new Matrix();
        switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotation.preRotate(90);
            break;

        case ExifInterface.ORIENTATION_ROTATE_180:
            rotation.preRotate(180);
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
            rotation.preRotate(270);
            break;
        }

        // Return new bitmap
        Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath");
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotation, true);
    } catch (Exception exception) {
        Log.d(TAG, "Couldn't fix bitmap orientation: " + exception.getMessage());
        Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath");
        return bitmap;
    }
}

From source file:Main.java

public static int[] getRotation(String imgPath) {
    int[] rs = new int[2];
    int rotation = 0;
    int flip = 0;
    try {/*w  w w .  j a va2s.c  o  m*/
        ExifInterface exif = new ExifInterface(imgPath);
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (exifOrientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            flip = 1;
        case ExifInterface.ORIENTATION_NORMAL:
            rotation = 0;
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            flip = 1;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotation = 90;
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            flip = 1;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotation = 180;
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            flip = 1;
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotation = 270;
            break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    rs[0] = rotation;
    rs[1] = flip;
    return rs;
}

From source file:Main.java

public static int getOrientation(final String imagePath) {
    int rotate = 0;
    try {//  ww w . j ava 2s. c  o m
        File imageFile = new File(imagePath);
        ExifInterface exif = new 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;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rotate;
}

From source file:Main.java

private static int getExifOrientation(String filePath) {
    ExifInterface exif;
    int orientation = 0;
    try {//ww  w  .j  ava2 s.c  om
        exif = new ExifInterface(filePath);
        orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return orientation;
}

From source file:Main.java

/**
 * To avoid problems with rotated videos retrieved from camera
 * @param bitmap/*w  w w .  j  a  va 2s .  com*/
 * @param filePath
 * @return
 */
public static Bitmap rotateImage(Bitmap bitmap, String filePath) {
    Bitmap resultBitmap = bitmap;

    try {
        ExifInterface exifInterface = new ExifInterface(filePath);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

        Matrix matrix = new Matrix();

        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            matrix.postRotate(ExifInterface.ORIENTATION_ROTATE_90);
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            matrix.postRotate(ExifInterface.ORIENTATION_ROTATE_180);
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            matrix.postRotate(ExifInterface.ORIENTATION_ROTATE_270);
        }

        // Rotate the bitmap
        resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    } catch (Exception exception) {
        Log.d("AndroidTouchGallery", "Could not rotate the image");
    }
    return resultBitmap;
}

From source file:Main.java

public static int getOrientationFromExif(String localPath) {
    ExifInterface exif = null;
    int orientation = 0;
    try {//from   w  ww .j av  a2 s  . c  o m
        exif = new ExifInterface(localPath);
        orientation = exif.getAttributeInt("Orientation", 0);
    } catch (IOException ex) {
    }
    return orientation;
}

From source file:Main.java

private static int getRotationFromCamera(Context context, Uri imageFile) {
    int rotate = 0;
    try {//from w w w.j  a v a2  s .c  o m

        context.getContentResolver().notifyChange(imageFile, null);
        ExifInterface exif = new ExifInterface(imageFile.getPath());
        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;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rotate;
}

From source file:Main.java

public static int getExifOrientation(String filepath) {
    int degree = 0;
    try {//from   w  w  w  .j  a va 2 s.c om
        ExifInterface exif = new ExifInterface(filepath);
        if (exif != null) {
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
            if (orientation != -1) {
                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    degree = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    degree = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    degree = 90;
                    break;
                }
            }
        }
        return degree;
    } catch (IOException ex) {
        Log.e("ExifOrientation", "cannot read exif", ex);
    }
    return degree;
}

From source file:Main.java

public static int readPictureDegree(String path) {
    int degree = 0;
    try {//from   w w  w .  java  2s.c  o m
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
        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;
        case ExifInterface.ORIENTATION_NORMAL:

            degree = 0;
            break;
        case ExifInterface.ORIENTATION_UNDEFINED:

            degree = 0;
            break;
        case -1:

            degree = 0;
            break;
        }
    } catch (IOException e) {

        e.printStackTrace();
    }

    return degree;
}

From source file:Main.java

public static int getCameraPhotoOrientation(Uri imageUri) {
    int rotate = 0;
    try {/* w w  w.  j  a  v a  2s . co  m*/
        File imageFile = new File(imageUri.getPath());
        ExifInterface exif = new 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;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rotate;
}