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

private static int getExifOrientation(String src) throws Exception {
    ExifInterface exifInterface = new ExifInterface(src);
    return exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
}

From source file:Main.java

public static int getImageOrientation(String uri) throws IOException {
    ExifInterface exif = new ExifInterface(uri);
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    return orientation;
}

From source file:Main.java

public static int getImageOrientation(String uri) {
    if (!new File(uri).exists()) {
        return 0;
    }//from   ww w  .ja  va2s  . com
    try {
        ExifInterface exif = new ExifInterface(uri);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        return orientation;
    } catch (Exception e) {
    }
    return 0;
}

From source file:Main.java

public static int getOrientationFromExif(File imgFile) throws IOException {
    ExifInterface exif = new ExifInterface(imgFile.getCanonicalPath());
    return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
}

From source file:Main.java

/**
 * Get Image Orientation from file//  w w  w  .  ja  va  2s .c  o m
 *
 * @param imageFile File for which orientation is changed
 * @return Current Orientation
 */
public static int getBitmapOrientation(File imageFile) {
    try {
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
    } catch (IOException e) {
    }
    return 0;
}

From source file:Main.java

/**
 * <pre>//from w  w w.j a  va2  s  .c  o  m
 * 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;
}

From source file:Main.java

public static int getFileExifDegree(String path) {
    try {//from ww  w .  j  av  a2s  .c  o  m
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static Bitmap fixBitmapOrientation(Uri uri, Bitmap bmp) throws IOException {
    ExifInterface ei = new ExifInterface(uri.getPath());
    int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        return rotateBitmap(bmp, 90);
    case ExifInterface.ORIENTATION_ROTATE_180:
        return rotateBitmap(bmp, 180);
    case ExifInterface.ORIENTATION_ROTATE_270:
        return rotateBitmap(bmp, 270);
    }//  w  w w.  ja v  a2 s .  co m

    return bmp;
}

From source file:Main.java

public static int getImageOrientation(String imagePath) {
    try {/*from w  w  w .  j a  v a2 s.  co m*/
        if (imagePath != null) {
            ExifInterface exif = new ExifInterface(imagePath);
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);
            switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                return 90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                return 180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                return 270;
            }
        }
    } catch (IOException e) {

    }
    return 0;
}

From source file:Main.java

public static int readPictureDegree(String path) {
    int degree = 0;
    try {/* w w  w . j av a2 s. co  m*/
        ExifInterface exifInterface = new ExifInterface(path);
        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;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return degree;
}