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 getImageDegree(String path) {
    int degree = 0;
    try {//from  w  ww.j a  va2 s. 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:
            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

private static int getExifOrientation(String filePath) {
    int degree = 0;
    try {//from   w  ww.  ja  v  a 2 s .co  m
        ExifInterface exif = new ExifInterface(filePath);
        int result = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
        switch (result) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            degree = 90;
            break;

        case ExifInterface.ORIENTATION_ROTATE_180:
            degree = 180;
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
            degree = 270;
            break;

        default:
            break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}

From source file:Main.java

public static int getRotation(String jpegFilePath) {
    int degrees = 0;
    try {//ww  w  .  j a  v a 2  s  .c o  m
        ExifInterface exifInterface = new ExifInterface(jpegFilePath);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            degrees = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            degrees = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            degrees = 270;
            break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degrees;
}

From source file:Main.java

public static int getOrientation(final Uri photoUri) {
    ExifInterface exifInterface = null;//from w w w . j a  v  a  2 s  .  c om
    try {
        exifInterface = new ExifInterface(photoUri.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
}

From source file:Main.java

public static int getImageOrientation(String imagePath) {
    try {/*from w w w . j a v  a2s  . c  o  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 synchronized static int getPhotoOrientationDegree(String filepath) {
    int degree = 0;
    ExifInterface exif = null;//w  w w. j a  v a 2  s .co m

    try {
        exif = new ExifInterface(filepath);
    } catch (IOException e) {
        // Log.d(PhotoUtil.class.getSimpleName(), "Error: "+e.getMessage());
    }

    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;
            }

        }
    }
    // Log.d(PhotoUtil.class.getSimpleName(), "Photo Degree: "+degree);
    return degree;
}

From source file:Main.java

public static int[] getRotation(String imgPath) {
    int[] rs = new int[2];
    int rotation = 0;
    int flip = 0;
    try {//from   www  . j  a  va 2s .  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 boolean copyExifRotation(File sourceFile, File destFile) {
    if (sourceFile == null || destFile == null)
        return false;
    try {/*from w  w  w . java2  s. c  o  m*/
        ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
        ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
        exifDest.setAttribute(ExifInterface.TAG_ORIENTATION,
                exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
        exifDest.saveAttributes();
        return true;
    } catch (IOException e) {
        return false;
    }
}

From source file:Main.java

public static Bitmap rotateByExifInfo(Bitmap source, String path) {
    try {//from   w w w  .  jav a 2  s  . c o  m
        ExifInterface exifInterface = new ExifInterface(path);
        String tagName = ExifInterface.TAG_ORIENTATION;
        int defaultValue = ExifInterface.ORIENTATION_NORMAL;
        int orientation = exifInterface.getAttributeInt(tagName, defaultValue);
        switch (orientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            return source;
        case ExifInterface.ORIENTATION_ROTATE_90:
            return rotate(source, 90);
        case ExifInterface.ORIENTATION_ROTATE_180:
            return rotate(source, 180);
        case ExifInterface.ORIENTATION_ROTATE_270:
            return rotate(source, 270f);
        default:
            return source;
        }
    } catch (Exception e) {
        return source;
    }
}

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);
    }/*ww w  . j ava 2 s . com*/

    return bmp;
}