Example usage for android.media ExifInterface ORIENTATION_ROTATE_90

List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_90

Introduction

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

Prototype

int ORIENTATION_ROTATE_90

To view the source code for android.media ExifInterface ORIENTATION_ROTATE_90.

Click Source Link

Usage

From source file:Main.java

public static int getExifRotation(File imageFile) {
    if (imageFile == null)
        return 0;
    try {//from   w ww . j  a  va2s  .  co 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

public static int getImageOrientation(String imagePath) {
    try {/*w  w  w . ja v a  2s.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 static int getExifOrientation(String filepath) {
    int degree = 0;
    try {// w w w.j  a  va2 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

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

    return bmp;
}

From source file:Main.java

public static int getExifOrientation(String filepath) {
    int degree = 0;
    ExifInterface exif = null;//from w  ww.j a va2 s  .co  m
    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 int getExifRotation(String imgPath) {
    try {//from   w  w  w .j a  v  a 2 s.  com
        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

/**
 * Extracts the EXIF rotation tag of an image file.
 *
 * @param filePath Path to the image file
 * @return Rotation in degrees/*from w w w  .  j a va2  s. com*/
 * @throws IOException
 */
public static int getExifRotation(String filePath) throws IOException {
    ExifInterface exif = new ExifInterface(filePath);

    int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

    switch (exifOrientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        return 90;
    case ExifInterface.ORIENTATION_ROTATE_180:
        return 180;
    case ExifInterface.ORIENTATION_ROTATE_270:
        return 270;
    default:
        return 0;
    }
}

From source file:Main.java

public synchronized static int getPhotoOrientationDegree(String filepath) {
    int degree = 0;
    ExifInterface exif = null;// w  ww .  ja v a2 s .  c  om

    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 getRotationAngle(String photoPath) {
    ExifInterface ei = null;//from ww  w .j a v a2s .  c  o m
    try {
        ei = new ExifInterface(photoPath);
    } catch (IOException e) {
        Log.e(TAG, "Unexpected error occurred when getting rotation angle.");
    }
    int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        Log.d(TAG, "90 Degrees rotation needed");
        return 90;
    case ExifInterface.ORIENTATION_ROTATE_180:
        Log.d(TAG, "180 Degrees rotation needed");
        return 180;
    case ExifInterface.ORIENTATION_ROTATE_270:
        Log.d(TAG, "270 Degrees rotation needed");
        return 270;
    case ExifInterface.ORIENTATION_NORMAL:
    default:
        Log.d(TAG, "0 Degrees rotation needed");
        return 0;
    }
}

From source file:Main.java

public static Bitmap rotateByExifInfo(Bitmap source, String path) {
    try {/*from   w  ww.  ja va2  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;
    }
}