Example usage for android.media ExifInterface ExifInterface

List of usage examples for android.media ExifInterface ExifInterface

Introduction

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

Prototype

public ExifInterface(InputStream inputStream) throws IOException 

Source Link

Document

Reads Exif tags from the specified image input stream.

Usage

From source file:Main.java

public static int getImageOrientation(String uri) {
    if (!new File(uri).exists()) {
        return 0;
    }//w w  w . j  a v a  2 s  .c o m
    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 getExifRotation(String imgPath) {
    try {//from  w ww  . j a  va  2  s. c  o  m
        ExifInterface exif = new ExifInterface(imgPath);
        String rotationAmount = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
        if (!TextUtils.isEmpty(rotationAmount)) {
            int rotationParam = Integer.parseInt(rotationAmount);
            switch (rotationParam) {
            case ExifInterface.ORIENTATION_NORMAL:
                return 0;
            case ExifInterface.ORIENTATION_ROTATE_90:
                return 90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                return 180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                return 270;
            default:
                return 0;
            }
        } else {
            return 0;
        }
    } catch (Exception ex) {
        return 0;
    }
}

From source file:Main.java

public static int getExifOrientation(String filepath) {
    int degree = 0;
    ExifInterface exif = null;/*from   w  w w  .j  av a 2  s.c  om*/
    try {
        exif = new ExifInterface(filepath);
    } catch (IOException ex) {
    }
    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 = 270;
                break;
            }
        }
    }
    return degree;
}

From source file:Main.java

public static float[] getGeoLocationFromPhoto(String photo_path) {
    ExifInterface exif;//from w  ww . ja va  2s .co m
    float latlong[] = { (float) 0.0, (float) 0.0 };
    try {
        exif = new ExifInterface(photo_path);
        exif.getLatLong(latlong);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return latlong;
}

From source file:Main.java

public static int getExifOrientation(String filepath) {
    int degree = 0;
    try {//from   w w w.j  ava2 s  . c o m
        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

private static int getExifOrientation(String filePath) {
    ExifInterface exif;/* ww  w .j a  v a 2 s. co  m*/
    int orientation = 0;
    try {
        exif = new ExifInterface(filePath);
        orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return orientation;
}

From source file:Main.java

public static int getRotationFromExif(Context context, String bitmapPath) {
    try {//from  ww  w.  j  a  v a  2s .  c  o  m
        ExifInterface ei = new ExifInterface(bitmapPath);
        int exifOrientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_UNDEFINED);

        switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        case ExifInterface.ORIENTATION_NORMAL:
            return 0;
        }
    } catch (Exception e) {

    }

    return -1;
}

From source file:Main.java

public static int getExifRotation(File imageFile) {
    if (imageFile == null)
        return 0;
    try {//w w  w.java 2  s  .c  o m
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        // We only recognize a subset of orientation tag values
        switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        default:
            return ExifInterface.ORIENTATION_UNDEFINED;
        }
    } catch (IOException e) {
        return 0;
    }
}

From source file:Main.java

private static int readPictureDegree(String path) {
    int degree = 0;
    try {/*from w  w  w . j  a  va 2 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 (IOException e) {
        e.printStackTrace();
    }
    return degree;
}

From source file:Main.java

public final static int getDegress(String path) {
    int degree = 0;
    try {/*from ww w  . ja v a2s  .com*/
        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 (IOException e) {
        e.printStackTrace();
    }
    return degree;
}