Android Camera image rotated

fabiodelorenzo
Posts: 65
Joined: Thu Oct 03, 2013 5:54 pm

Android Camera image rotated

Postby fabiodelorenzo » Mon Jun 27, 2016 7:42 pm

Most phone cameras are landscape, meaning if you take the photo in portrait, the resulting photos will be rotated 90 degrees.
In this case, the camera software should populate the EXIF data with the orientation that the photo should be viewed in.

Code: Select all

ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

switch(orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotateImage(bitmap, 90);
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotateImage(bitmap, 180);
        break;
    // etc.
}


Here is the rotateImage method:

Code: Select all

public static Bitmap rotateImage(Bitmap source, float angle) {
    Bitmap retVal;

    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    retVal = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);

    return retVal;
}

Return to “Camera”

Who is online

Users browsing this forum: No registered users and 1 guest