Example usage for android.media ExifInterface ORIENTATION_ROTATE_270

List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_270

Introduction

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

Prototype

int ORIENTATION_ROTATE_270

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

Click Source Link

Usage

From source file:Main.java

private static int getBitmapRotation(String filePath) {
    int rotation = 0;
    switch (getExifOrientation(filePath)) {
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotation = 180;/*  w w  w .  ja v a  2 s. co 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

static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) {
    Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath");
    try {//  www.  j  a v  a2s.c  o m
        // Get orientation from EXIF
        ExifInterface exif = new ExifInterface(filePath);
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        // Compute rotation matrix
        Matrix rotation = new Matrix();
        switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotation.preRotate(90);
            break;

        case ExifInterface.ORIENTATION_ROTATE_180:
            rotation.preRotate(180);
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
            rotation.preRotate(270);
            break;
        }

        // Return new bitmap
        Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath");
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotation, true);
    } catch (Exception exception) {
        Log.d(TAG, "Couldn't fix bitmap orientation: " + exception.getMessage());
        Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath");
        return bitmap;
    }
}

From source file:Main.java

public static int getOrientation(final String imagePath) {
    int rotate = 0;
    try {//from w ww .  j  a va2  s .  c  om
        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

private static int getRotationFromCamera(Context context, Uri imageFile) {
    int rotate = 0;
    try {/*w w  w  .  ja v a 2 s. c  o  m*/

        context.getContentResolver().notifyChange(imageFile, null);
        ExifInterface exif = new ExifInterface(imageFile.getPath());
        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

/**
 * Checks if the orientation of the image is correct, if it's not it will rotate the image
 *
 * @param pBitmap/* ww w.j  a va  2  s  .  c o m*/
 *        The bitmap to check the orientation for
 * @param pPath
 *        The path to the image, used to load the exif interface
 * @return Bitmap in the correct orientation
 */
public static Bitmap imageOreintationValidator(Bitmap pBitmap, String pPath) {
    ExifInterface ei;
    try {
        ei = new ExifInterface(pPath);
        int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            pBitmap = rotateImage(pBitmap, 90);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            pBitmap = rotateImage(pBitmap, 180);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            pBitmap = rotateImage(pBitmap, 270);
            break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return pBitmap;
}

From source file:Main.java

/**
 * Get the orientation rotate degree of an image file.
 * /*  w w w.  j av a2 s. c o 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 getOrientation(Context context, Uri photoUri, File file) {
    /* it's on the external media. */
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
    if (cursor != null && cursor.getCount() != 1) {
        cursor.moveToFirst();/*www  .  j a  v a2s. c o  m*/
        return cursor.getInt(0);
    }

    int rotate = 0;
    ExifInterface exif = null;

    try {
        exif = new ExifInterface(file == null ? getPath(context, photoUri) : file.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    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;
    case ExifInterface.ORIENTATION_NORMAL:
        rotate = 0;
        break;
    }
    return rotate;
}

From source file:Main.java

public static int getDegress(String path) {
    int degree = 0;
    try {//from ww w . j  av a2  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

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   www .j  a v  a  2 s  .  c om*/
        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

public static int[] getRotation(String imgPath) {
    int[] rs = new int[2];
    int rotation = 0;
    int flip = 0;
    try {//  w w  w .  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;
}