Java Code Examples for android.media.ExifInterface#ORIENTATION_FLIP_VERTICAL

The following examples show how to use android.media.ExifInterface#ORIENTATION_FLIP_VERTICAL . 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: BitmapProcessing.java    From Effects-Pro with MIT License 6 votes vote down vote up
public static Bitmap modifyOrientation(Bitmap bitmap, String image_url) throws IOException {
	ExifInterface ei = new ExifInterface(image_url);
	int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

	switch (orientation) {
	case ExifInterface.ORIENTATION_ROTATE_90:
		return rotate(bitmap, 90);

	case ExifInterface.ORIENTATION_ROTATE_180:
		return rotate(bitmap, 180);

	case ExifInterface.ORIENTATION_ROTATE_270:
		return rotate(bitmap, 270);

	case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
		return flip(bitmap, true, false);

	case ExifInterface.ORIENTATION_FLIP_VERTICAL:
		return flip(bitmap, false, true);

	default:
		return bitmap;
	}
}
 
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: MediaStoreServiceImpl.java    From AndroidMvc with Apache License 2.0 6 votes vote down vote up
private ImageDTO.Orientation translateOrientation(int orientation) {
    switch (orientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            return ImageDTO.Orientation.FLIP_HORIZONTAL;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            return ImageDTO.Orientation.FLIP_VERTICAL;
        case ExifInterface.ORIENTATION_NORMAL:
            return ImageDTO.Orientation.NORMAL;
        case ExifInterface.ORIENTATION_ROTATE_90:
            return ImageDTO.Orientation.ROTATE_90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return ImageDTO.Orientation.ROTATE_180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return ImageDTO.Orientation.ROTATE_270;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            return ImageDTO.Orientation.TRANSPOSE;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            return ImageDTO.Orientation.TRANSVERSE;
        default:
            return ImageDTO.Orientation.UNDEFINED;
    }
}
 
Example 4
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 5
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 6
Source File: Utils.java    From SimpleCropView with MIT License 5 votes vote down vote up
public static Matrix getMatrixFromExifOrientation(int orientation) {
  Matrix matrix = new Matrix();
  switch (orientation) {
    case ExifInterface.ORIENTATION_UNDEFINED:
      break;
    case ExifInterface.ORIENTATION_NORMAL:
      break;
    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
      matrix.postScale(-1.0f, 1.0f);
      break;
    case ExifInterface.ORIENTATION_ROTATE_180:
      matrix.postRotate(180.0f);
      break;
    case ExifInterface.ORIENTATION_FLIP_VERTICAL:
      matrix.postScale(1.0f, -1.0f);
      break;
    case ExifInterface.ORIENTATION_ROTATE_90:
      matrix.postRotate(90.0f);
      break;
    case ExifInterface.ORIENTATION_TRANSVERSE:
      matrix.postRotate(-90.0f);
      matrix.postScale(1.0f, -1.0f);
      break;
    case ExifInterface.ORIENTATION_TRANSPOSE:
      matrix.postRotate(90.0f);
      matrix.postScale(1.0f, -1.0f);
      break;
    case ExifInterface.ORIENTATION_ROTATE_270:
      matrix.postRotate(-90.0f);
      break;
  }
  return matrix;
}
 
Example 7
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 8
Source File: BaseImageDecoder.java    From android-open-project-demo 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 9
Source File: BaseImageDecoder.java    From WliveTV 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: OrientedDrawableTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testCreation_flipVertical() {
  OrientedDrawable drawable =
      new OrientedDrawable(mDrawable, 0, ExifInterface.ORIENTATION_FLIP_VERTICAL);
  drawable.setBounds(mBounds);
  drawable.draw(mCanvas);

  Matrix expectedMatrix = new Matrix();
  expectedMatrix.setScale(1, -1);
  assertFalse(drawable.mRotationMatrix.isIdentity());
  AndroidGraphicsTestUtils.assertEquals(expectedMatrix, drawable.mRotationMatrix);
  verifySetBounds(expectedMatrix);
}
 
Example 11
Source File: Utils.java    From Android-CropView with Apache License 2.0 5 votes vote down vote up
public static Matrix getMatrixFromExifOrientation(int orientation) {
    Matrix matrix = new Matrix();
    switch (orientation) {
        case ExifInterface.ORIENTATION_UNDEFINED:
            break;
        case ExifInterface.ORIENTATION_NORMAL:
            break;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            matrix.postScale(-1.0f, 1.0f);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.postRotate(180.0f);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            matrix.postScale(1.0f, -1.0f);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            matrix.postRotate(90.0f);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            matrix.postRotate(-90.0f);
            matrix.postScale(1.0f, -1.0f);
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            matrix.postRotate(90.0f);
            matrix.postScale(1.0f, -1.0f);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            matrix.postRotate(-90.0f);
            break;
    }
    return matrix;
}
 
Example 12
Source File: BaseImageDecoder.java    From Android-Application-ZJB 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 13
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 14
Source File: BitmapLoadUtils.java    From Matisse-Kotlin with Apache License 2.0 5 votes vote down vote up
public static int exifToTranslation(int exifOrientation) {
    int translation;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        case ExifInterface.ORIENTATION_TRANSPOSE:
        case ExifInterface.ORIENTATION_TRANSVERSE:
            translation = -1;
            break;
        default:
            translation = 1;
    }
    return translation;
}
 
Example 15
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 16
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 17
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 18
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 19
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 20
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;
    }
}