Java Code Examples for android.media.ExifInterface#ORIENTATION_FLIP_HORIZONTAL

The following examples show how to use android.media.ExifInterface#ORIENTATION_FLIP_HORIZONTAL . 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 7 votes vote down vote up
/**
 * Returns the transformation matrix if the orientation corresponds to one present in {@link
 * #INVERTED_EXIF_ORIENTATIONS}, else null.
 *
 * @param orientation the exif orientation
 * @return the transformation matrix if inverted orientation, else null.
 */
@Nullable
private static Matrix getTransformationMatrixFromInvertedExif(final int orientation) {
  Matrix matrix = new Matrix();
  switch (orientation) {
    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
      matrix.setScale(-1, 1);
      break;
    case ExifInterface.ORIENTATION_TRANSVERSE:
      matrix.setRotate(-90);
      matrix.postScale(-1, 1);
      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;
    default:
      return null;
  }
  return matrix;
}
 
Example 2
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 3
Source File: BaseImageDecoder.java    From BigApp_WordPress_Android 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 4
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 5
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 6
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 7
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 8
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 9
Source File: BaseImageDecoder.java    From android-project-wo2b 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 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 11
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 12
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 13
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 14
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 15
Source File: OrientedDrawableTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testCreation_flipHorizontal() {
  OrientedDrawable drawable =
      new OrientedDrawable(mDrawable, 0, ExifInterface.ORIENTATION_FLIP_HORIZONTAL);
  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 16
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 17
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 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: 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 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;
    }
}