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

/**
 * Scale a bitmap and correct the dimensions
 *
 * @param bitmap      Bitmap to scale/*from w w w.j a  va2s  .  co  m*/
 * @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 int getRotateDegree(String path) {
    int result = 0;
    try {/*from w w w.j a  v  a 2s.  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 {//  www.  j  a va2s.com
        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;
}

From source file:Main.java

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

    ExifInterface exif;//from   ww  w . j a v a  2s.  co 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

@TargetApi(Build.VERSION_CODES.ECLAIR)
public static int getImageDegree(String path) {
    int degree = 0;
    try {/* w  w  w. jav  a  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

public static Bitmap rotateBitmapFromExif(String filePath, Bitmap bitmap) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from w  ww. ja  v  a 2  s. com*/
    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 getExifDegree(String filepath) {
    int degree = 0;
    ExifInterface exif;//from  ww w .j  a  va 2  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;/*from w  ww  .  jav  a 2  s .com*/
    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;/*w ww. j  a  v  a 2s  .c o  m*/
                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 getCameraPhotoOrientation(Uri imageUri) {
    int rotate = 0;
    try {//  w  w w .j av a  2  s .  c  om
        File imageFile = new File(imageUri.getPath());
        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;
}