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 rotateBitmapFromExif(String filePath, Bitmap bitmap) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;//  www .  ja v  a 2 s.  c  o m
    BitmapFactory.decodeFile(filePath, options);

    String orientString;
    try {
        ExifInterface exif = new ExifInterface(filePath);
        orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
    } catch (IOException e) {
        e.printStackTrace();
        return bitmap;
    }

    int orientation = (orientString != null) ? Integer.parseInt(orientString)
            : ExifInterface.ORIENTATION_NORMAL;
    int rotationAngle = 0, outHeight = 0, outWidth = 0;
    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotationAngle = 90;
        outHeight = bitmap.getWidth();
        outWidth = bitmap.getHeight();
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotationAngle = 180;
        outHeight = bitmap.getHeight();
        outWidth = bitmap.getWidth();
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotationAngle = 270;
        outHeight = bitmap.getWidth();
        outWidth = bitmap.getHeight();
        break;
    }

    if (rotationAngle == 0) {
        return bitmap;
    }

    Matrix matrix = new Matrix();
    matrix.setRotate(rotationAngle, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
    Bitmap rotateBitmap = Bitmap.createBitmap(bitmap, 0, 0, outWidth, outHeight, matrix, true);
    if (bitmap != rotateBitmap) {
        bitmap.recycle();
    }

    return rotateBitmap;
}

From source file:Main.java

/**
 * Get Image orientation from uri/*from   w  ww.  j  a  va2  s  .  c  o  m*/
 *
 * @param context  Context of image
 * @param photoUri Uri of image
 * @return
 */
public static int getOrientation(Context context, Uri photoUri) {
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    try {
        if (cursor.moveToFirst()) {
            if (cursor.getInt(0) == ORIENTATION_270)
                return ExifInterface.ORIENTATION_ROTATE_270;
            else if (cursor.getInt(0) == ORIENTATION_180)
                return ExifInterface.ORIENTATION_ROTATE_180;
            else if (cursor.getInt(0) == ORIENTATION_90)
                return ExifInterface.ORIENTATION_ROTATE_90;
        }
    } finally {
        cursor.close();
    }
    return -1;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
public static int getImageDegree(String path) {
    int degree = 0;
    try {/*from w w  w.j ava 2s. 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;
}

From source file:Main.java

public static int getExifDegree(String filepath) {
    int degree = 0;
    ExifInterface exif;//from  ww w  .  ja  va2 s . co m
    try {
        exif = new ExifInterface(filepath);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return 0;
    }

    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 getExifOrientation(String filepath) {
    int degree = 0;
    ExifInterface exif = null;/*  w  w w  . j  a v a  2  s  .c o m*/
    try {
        exif = new ExifInterface(filepath);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    if (exif != null) {
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
        if (orientation != -1) {
            // We only recognise a subset of orientation tag values.
            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 getExifOrientation(final ExifInterface exif) {
    int degree = 0;

    if (exif != null) {
        final int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
        if (orientation != -1) {
            switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;/*from  w ww . ja  va  2s .c om*/
                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 getOrientation(final String imagePath) {
    int rotate = 0;
    try {//  w  ww .  jav a  2s  .  c  o  m
        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 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();/*  w w w .  j  a  va 2  s.com*/
        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

private static int getRotationFromCamera(Context context, Uri imageFile) {
    int rotate = 0;
    try {/*from  w  w  w .  j av  a2s . 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

public static Matrix getRotationMatrixForImage(Context ctx, Uri contentUri) {

    String pathToImage = getAbsolutePathFromUri(ctx, contentUri);
    ExifInterface exif;/*from w w w  . j  av a2s. co  m*/
    try {
        exif = new ExifInterface(pathToImage);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
        Matrix matrix = new Matrix();
        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            matrix.postRotate(90);
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            matrix.postRotate(180);
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            matrix.postRotate(270);
        }
        return matrix;
    } catch (IOException e) {
        return new Matrix();
    }
}