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 Bitmap normalizeExifRotateBitmap(Bitmap bitmap, int orientation) {

    Matrix matrix = new Matrix();
    switch (orientation) {
    case ExifInterface.ORIENTATION_NORMAL:
        return bitmap;
    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        matrix.setScale(-1, 1);//from   ww  w.j  a v a2 s .c o m
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        matrix.setRotate(180);
        break;
    case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        matrix.setRotate(180);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_TRANSPOSE:
        matrix.setRotate(90);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        matrix.setRotate(90);
        break;
    case ExifInterface.ORIENTATION_TRANSVERSE:
        matrix.setRotate(-90);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        matrix.setRotate(-90);
        break;
    default:
        return bitmap;
    }
    try {
        Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
                true);
        bitmap.recycle();
        return bmRotated;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

/**
 * Get the orientation rotate degree of an image file.
 * /*from ww w .j  a  v  a 2s .  co m*/
 * @param soureFilePath
 *            The file path of the image.
 * @return The orientation rotate degree of an image file(90 or 180 or 270). <br>
 *         0, if the image file has no orientation rotate degree or the
 *         source file is not a valid image file.
 */
public static int getOrientationRotateDegree(String soureFilePath) {
    if (null == soureFilePath) {
        return 0;
    }

    try {
        ExifInterface exif = new ExifInterface(soureFilePath);
        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;
        }
        default: {
            return 0;
        }
        }

    } catch (IOException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) {
    int rotate = 0;
    try {/*w  w  w  .j  a  v a  2  s.co m*/
        context.getContentResolver().notifyChange(imageUri, null);
        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

public static int getDegress(String path) {
    int degree = 0;
    try {//from   w ww  .  j a va 2  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 getBitmapRotation(String filePath) {
    int rotation = 0;
    switch (getExifOrientation(filePath)) {
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotation = 180;//from ww w . j a va 2s .c  o  m
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotation = 90;
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotation = 270;
        break;
    }
    return rotation;
}

From source file:Main.java

/**
 * Scale a bitmap and correct the dimensions
 *
 * @param bitmap      Bitmap to scale//  ww  w.j av  a 2  s.  c om
 * @param width       width for scaling
 * @param height      height for scaling
 * @param orientation Current orientation of the Image
 * @return Scaled bitmap
 */
public static Bitmap getScaledBitmap(Bitmap bitmap, int width, int height, int orientation) {
    Matrix m = new Matrix();
    m.setRectToRect(new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()), new RectF(0, 0, width, height),
            Matrix.ScaleToFit.CENTER);
    if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
        m.postRotate(ORIENTATION_90);
    } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
        m.postRotate(ORIENTATION_180);
    } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
        m.postRotate(ORIENTATION_270);
    }
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
}

From source file:Main.java

public static Matrix rotateImage(Context context, Uri imageUri, File f) {
    Matrix matrix = new Matrix();
    try {/*w w w.ja  v a 2s  . com*/
        if (imageUri != null) {
            context.getContentResolver().notifyChange(imageUri, null);
        }
        ExifInterface exif = new ExifInterface(f.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            matrix.postRotate(270);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.postRotate(180);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            matrix.postRotate(90);
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return matrix;
}

From source file:Main.java

private static Bitmap turnPic(final String path, Bitmap bitmap) {

    ExifInterface exif;//from   w ww .j  ava2 s .c  om
    final int ninetyDegrees = 90;
    int rotationAngle = 0;
    Matrix matrix = new Matrix();

    if (path != null) {
        try {
            exif = new ExifInterface(path);
            int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);
            switch (exifOrientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotationAngle = ninetyDegrees;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotationAngle = ninetyDegrees * 2;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotationAngle = ninetyDegrees * 3;
                break;
            case ExifInterface.ORIENTATION_NORMAL:
            default:
                break;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return bitmap;
        }
        if (rotationAngle != 0) {
            matrix.postRotate(rotationAngle);
        }
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }
    return bitmap;
}

From source file:Main.java

public static int getRotateDegree(String path) {
    int result = 0;
    try {/*w  ww .j av a2  s .  com*/
        ExifInterface exif = new ExifInterface(path);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            result = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            result = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            result = 270;
            break;
        }
    } catch (IOException ignore) {
        return 0;
    }
    return result;
}

From source file:Main.java

public static int readPictureDegree(String path) {
    int degree = 0;
    try {//  w  w  w .j  a  v a2s.  co 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;
}