Java Code Examples for android.media.ExifInterface#ORIENTATION_TRANSPOSE

The following examples show how to use android.media.ExifInterface#ORIENTATION_TRANSPOSE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpegTranscoderUtils.java    From fresco with MIT License 6 votes vote down vote up
/** @return true if and only if given value is a valid EXIF orientation */
public static boolean isExifOrientationAllowed(int exifOrientation) {
  switch (exifOrientation) {
    case ExifInterface.ORIENTATION_NORMAL:
    case ExifInterface.ORIENTATION_ROTATE_90:
    case ExifInterface.ORIENTATION_ROTATE_180:
    case ExifInterface.ORIENTATION_ROTATE_270:
    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
    case ExifInterface.ORIENTATION_FLIP_VERTICAL:
    case ExifInterface.ORIENTATION_TRANSPOSE:
    case ExifInterface.ORIENTATION_TRANSVERSE:
      return true;
    default:
      return false;
  }
}
 
Example 2
Source File: BitmapLoadUtils.java    From Matisse-Kotlin with Apache License 2.0 6 votes vote down vote up
public static int exifToDegrees(int exifOrientation) {
    int rotation;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
        case ExifInterface.ORIENTATION_TRANSPOSE:
            rotation = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            rotation = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
        case ExifInterface.ORIENTATION_TRANSVERSE:
            rotation = 270;
            break;
        default:
            rotation = 0;
    }
    return rotation;
}
 
Example 3
Source File: OrientedDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
protected void onBoundsChange(Rect bounds) {
  Drawable underlyingDrawable = getCurrent();
  if (mRotationAngle > 0
      || (mExifOrientation != ExifInterface.ORIENTATION_UNDEFINED
          && mExifOrientation != ExifInterface.ORIENTATION_NORMAL)) {
    switch (mExifOrientation) {
      case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        mRotationMatrix.setScale(-1, 1);
        break;
      case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        mRotationMatrix.setScale(1, -1);
        break;
      case ExifInterface.ORIENTATION_TRANSPOSE:
        mRotationMatrix.setRotate(270, bounds.centerX(), bounds.centerY());
        mRotationMatrix.postScale(1, -1);
        break;
      case ExifInterface.ORIENTATION_TRANSVERSE:
        mRotationMatrix.setRotate(270, bounds.centerX(), bounds.centerY());
        mRotationMatrix.postScale(-1, 1);
        break;
      default:
        mRotationMatrix.setRotate(mRotationAngle, bounds.centerX(), bounds.centerY());
        break;
    }

    // Set the rotated bounds on the underlying drawable
    mTempMatrix.reset();
    mRotationMatrix.invert(mTempMatrix);
    mTempRectF.set(bounds);
    mTempMatrix.mapRect(mTempRectF);
    underlyingDrawable.setBounds(
        (int) mTempRectF.left,
        (int) mTempRectF.top,
        (int) mTempRectF.right,
        (int) mTempRectF.bottom);
  } else {
    underlyingDrawable.setBounds(bounds);
  }
}
 
Example 4
Source File: OrientedDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
public int getIntrinsicWidth() {
  if (mExifOrientation == ExifInterface.ORIENTATION_TRANSPOSE
      || mExifOrientation == ExifInterface.ORIENTATION_TRANSVERSE
      || mRotationAngle % 180 != 0) {
    return super.getIntrinsicHeight();
  } else {
    return super.getIntrinsicWidth();
  }
}
 
Example 5
Source File: OrientedDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
public int getIntrinsicHeight() {
  if (mExifOrientation == ExifInterface.ORIENTATION_TRANSPOSE
      || mExifOrientation == ExifInterface.ORIENTATION_TRANSVERSE
      || mRotationAngle % 180 != 0) {
    return super.getIntrinsicWidth();
  } else {
    return super.getIntrinsicHeight();
  }
}
 
Example 6
Source File: ImagePreProcessor.java    From HttpFileUploaderAndDownloader with Apache License 2.0 5 votes vote down vote up
/**
 * 获取照片的旋转角度等信息
 *
 * @param file
 * @return
 */
private static ExifInfo defineExifOrientation(String file) {
    int rotation = 0;
    boolean flip = false;
    try {
        ExifInterface exif = new ExifInterface(file);
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (exifOrientation) {
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                flip = true;
            case ExifInterface.ORIENTATION_NORMAL:
                rotation = 0;
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new ExifInfo(rotation, flip);
}
 
Example 7
Source File: CloseableStaticBitmap.java    From fresco with MIT License 5 votes vote down vote up
/** @return height of the image */
@Override
public int getHeight() {
  if (mRotationAngle % 180 != 0
      || mExifOrientation == ExifInterface.ORIENTATION_TRANSPOSE
      || mExifOrientation == ExifInterface.ORIENTATION_TRANSVERSE) {
    return getBitmapWidth(mBitmap);
  }
  return getBitmapHeight(mBitmap);
}
 
Example 8
Source File: BaseImageDecoder.java    From Roid-Library with Apache License 2.0 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri, String mimeType) {
    int rotation = 0;
    boolean flip = false;
    if ("image/jpeg".equalsIgnoreCase(mimeType) && Scheme.ofUri(imageUri) == Scheme.FILE) {
        try {
            ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
            int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);
            switch (exifOrientation) {
                case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                    flip = true;
                case ExifInterface.ORIENTATION_NORMAL:
                    rotation = 0;
                    break;
                case ExifInterface.ORIENTATION_TRANSVERSE:
                    flip = true;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotation = 90;
                    break;
                case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                    flip = true;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotation = 180;
                    break;
                case ExifInterface.ORIENTATION_TRANSPOSE:
                    flip = true;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotation = 270;
                    break;
            }
        } catch (IOException e) {
            L.w("Can't read EXIF tags from file [%s]", imageUri);
        }
    }
    return new ExifInfo(rotation, flip);
}
 
Example 9
Source File: BaseImageDecoder.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri) {
	int rotation = 0;
	boolean flip = false;
	try {
		ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
		int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
		switch (exifOrientation) {
			case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
				flip = true;
			case ExifInterface.ORIENTATION_NORMAL:
				rotation = 0;
				break;
			case ExifInterface.ORIENTATION_TRANSVERSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_90:
				rotation = 90;
				break;
			case ExifInterface.ORIENTATION_FLIP_VERTICAL:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_180:
				rotation = 180;
				break;
			case ExifInterface.ORIENTATION_TRANSPOSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_270:
				rotation = 270;
				break;
		}
	} catch (IOException e) {
		L.w("Can't read EXIF tags from file [%s]", imageUri);
	}
	return new ExifInfo(rotation, flip);
}
 
Example 10
Source File: BaseImageDecoder.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri) {
	int rotation = 0;
	boolean flip = false;
	try {
		ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
		int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
		switch (exifOrientation) {
			case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
				flip = true;
			case ExifInterface.ORIENTATION_NORMAL:
				rotation = 0;
				break;
			case ExifInterface.ORIENTATION_TRANSVERSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_90:
				rotation = 90;
				break;
			case ExifInterface.ORIENTATION_FLIP_VERTICAL:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_180:
				rotation = 180;
				break;
			case ExifInterface.ORIENTATION_TRANSPOSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_270:
				rotation = 270;
				break;
		}
	} catch (IOException e) {
		L.w("Can't read EXIF tags from file [%s]", imageUri);
	}
	return new ExifInfo(rotation, flip);
}
 
Example 11
Source File: OrientedDrawableTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testCreation_transpose() {
  OrientedDrawable drawable =
      new OrientedDrawable(mDrawable, 0, ExifInterface.ORIENTATION_TRANSPOSE);
  drawable.setBounds(mBounds);
  drawable.draw(mCanvas);

  Matrix expectedMatrix = new Matrix();
  expectedMatrix.setRotate(270, drawable.getBounds().centerX(), drawable.getBounds().centerY());
  expectedMatrix.postScale(1, -1);
  assertFalse(drawable.mRotationMatrix.isIdentity());
  AndroidGraphicsTestUtils.assertEquals(expectedMatrix, drawable.mRotationMatrix);
  verifySetBounds(expectedMatrix);
}
 
Example 12
Source File: DiskDecoder.java    From talk-android with MIT License 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri) {
    int rotation = 0;
    boolean flip = false;
    try {
        ExifInterface exif = new ExifInterface(ImageDownloader.Scheme.FILE.crop(imageUri));
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (exifOrientation) {
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                flip = true;
            case ExifInterface.ORIENTATION_NORMAL:
                rotation = 0;
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
        }
    } catch (IOException e) {
        L.w("Can't read EXIF tags from file [%s]", imageUri);
    }
    return new ExifInfo(rotation, flip);
}
 
Example 13
Source File: BitmapDecoder.java    From volley with Apache License 2.0 5 votes vote down vote up
private static ExifInfo defineExifOrientation(String imageUri) {
    int rotation = 0;
    boolean flip = false;
    try {
        ExifInterface exif = new ExifInterface(imageUri);
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (exifOrientation) {
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                flip = true;
            case ExifInterface.ORIENTATION_NORMAL:
                rotation = 0;
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
        }
    } catch (IOException e) {
        VolleyLog.e("Can't read EXIF tags from file [%s]", imageUri);
    }
    return new ExifInfo(rotation, flip);
}
 
Example 14
Source File: TransformationUtils.java    From giffun with Apache License 2.0 5 votes vote down vote up
static void initializeMatrixForRotation(int exifOrientation, Matrix matrix) {
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            matrix.setScale(-1, 1);
            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:
            // Do nothing.
    }
}
 
Example 15
Source File: BaseImageDecoder.java    From candybar with Apache License 2.0 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri) {
    int rotation = 0;
    boolean flip = false;
    try {
        ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (exifOrientation) {
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                flip = true;
            case ExifInterface.ORIENTATION_NORMAL:
                rotation = 0;
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                flip = true;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
        }
    } catch (IOException e) {
        L.w("Can't read EXIF tags from file [%s]", imageUri);
    }
    return new ExifInfo(rotation, flip);
}
 
Example 16
Source File: BitmapUtils.java    From Cirrus_depricated with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Rotate bitmap according to EXIF orientation. 
 * Cf. http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ 
 * @param bitmap Bitmap to be rotated
 * @param storagePath Path to source file of bitmap. Needed for EXIF information. 
 * @return correctly EXIF-rotated bitmap
 */
public static Bitmap rotateImage(Bitmap bitmap, String storagePath){
    Bitmap resultBitmap = bitmap;

    try
    {
        ExifInterface exifInterface = new ExifInterface(storagePath);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

        Matrix matrix = new Matrix();

        // 1: nothing to do
        
        // 2
        if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL)
        {
            matrix.postScale(-1.0f, 1.0f);
        }
        // 3
        else if (orientation == ExifInterface.ORIENTATION_ROTATE_180)
        {
            matrix.postRotate(180);
        }
        // 4
        else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL)
        {
            matrix.postScale(1.0f, -1.0f);
        }
        // 5
        else if (orientation == ExifInterface.ORIENTATION_TRANSPOSE)
        {
            matrix.postRotate(-90);
            matrix.postScale(1.0f, -1.0f);
        }
        // 6
        else if (orientation == ExifInterface.ORIENTATION_ROTATE_90)
        {
            matrix.postRotate(90);
        }
        // 7
        else if (orientation == ExifInterface.ORIENTATION_TRANSVERSE)
        {
            matrix.postRotate(90);
            matrix.postScale(1.0f, -1.0f);
        }
        // 8
        else if (orientation == ExifInterface.ORIENTATION_ROTATE_270)
        {
            matrix.postRotate(270);
        } 
        
        // Rotate the bitmap
        resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        if (resultBitmap != bitmap) {
            bitmap.recycle();
        }
    }
    catch (Exception exception)
    {
        Log_OC.e("BitmapUtil", "Could not rotate the image: " + storagePath);
    }
    return resultBitmap;
}
 
Example 17
Source File: UserPicture.java    From SO-2169649 with Apache License 2.0 4 votes vote down vote up
private boolean getInformationFromFileSystem() throws IOException {
    path = uri.getPath();

    if (path == null)
        return false;

    ExifInterface exif = new ExifInterface(path);
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
            ExifInterface.ORIENTATION_NORMAL);

    this.orientation = new Matrix();
    switch (orientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            /* Identity matrix */
            break;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            this.orientation.setScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            this.orientation.setRotate(180);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            this.orientation.setScale(1, -1);
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            this.orientation.setRotate(90);
            this.orientation.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            this.orientation.setRotate(90);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            this.orientation.setRotate(-90);
            this.orientation.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            this.orientation.setRotate(-90);
            break;
    }

    return true;
}
 
Example 18
Source File: MainActivity.java    From MOAAP with MIT License 4 votes vote down vote up
public static Bitmap rotateBitmap(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);
                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;
        }

    }
 
Example 19
Source File: ImageUtils.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private Bitmap rotateBitmap(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);
            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 ignore) {
        return null;
    }
}
 
Example 20
Source File: MediaUtils.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
private static Bitmap rotateBitmap(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);
            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;
    }
}