Example usage for android.media ExifInterface ORIENTATION_NORMAL

List of usage examples for android.media ExifInterface ORIENTATION_NORMAL

Introduction

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

Prototype

int ORIENTATION_NORMAL

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

Click Source Link

Usage

From source file:Main.java

public static int getDegress(String path) {
    int degree = 0;
    try {//  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 Bitmap turnPic(final String path, Bitmap bitmap) {

    ExifInterface exif;/*from   w  w  w. j a  v a  2  s .c  o  m*/
    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 Bitmap rotateBitmapFromExif(String filePath, Bitmap bitmap) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from w ww  .  j av a2  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

public static int getRotateDegree(String path) {
    int result = 0;
    try {/*  w  w  w .j  a  v a 2s  .  c om*/
        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 getOrientation(final String imagePath) {
    int rotate = 0;
    try {//from w ww.  j a v  a2  s  . co 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

private static int getRotationFromCamera(Context context, Uri imageFile) {
    int rotate = 0;
    try {/*from   w  ww .j  a  va2s. com*/

        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 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();//from ww w.j  a va2s . 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 getRotationAngle(String photoPath) {
    ExifInterface ei = null;/*from www .  j  ava2 s.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

@TargetApi(Build.VERSION_CODES.ECLAIR)
public static int getImageDegree(String path) {
    int degree = 0;
    try {//from   w  w  w  . j av a 2 s  .  co  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 int defineExifOrientation(Uri imageUri, String mimeType) {
    int rotation = 0;
    if ("image/jpeg".equalsIgnoreCase(mimeType) && "file".equals(imageUri.getScheme())) {
        try {/*from   ww w.  java 2  s .  c  om*/
            ExifInterface exif = new ExifInterface(imageUri.getPath());
            int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);
            Log.e("dsd", "exifOrientation:" + exifOrientation);
            switch (exifOrientation) {
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            case ExifInterface.ORIENTATION_NORMAL:
                rotation = 0;
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
            }
        } catch (IOException e) {
            Log.e("dsd", "Can't read EXIF tags from file [%s]" + imageUri);
        }
    }
    return rotation;
}