/** * Rotate and/or flip the image to match the given exif orientation. * * @param pool A pool that may or may not contain an image of the necessary * dimensions. * @param inBitmap The bitmap to rotate/flip. * @param exifOrientation the exif orientation [1-8]. * @return The rotated and/or flipped image or toOrient if no rotation or flip was necessary. */ public static Bitmap rotateImageExif(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int exifOrientation) { if (!isExifOrientationRequired(exifOrientation)) { return inBitmap; } final Matrix matrix = new Matrix(); initializeMatrixForRotation(exifOrientation, matrix); // From Bitmap.createBitmap. final RectF newRect = new RectF(0, 0, inBitmap.getWidth(), inBitmap.getHeight()); matrix.mapRect(newRect); final int newWidth = Math.round(newRect.width()); final int newHeight = Math.round(newRect.height()); Bitmap.Config config = getNonNullConfig(inBitmap); Bitmap result = pool.get(newWidth, newHeight, config); matrix.postTranslate(-newRect.left, -newRect.top); result.setHasAlpha(inBitmap.hasAlpha()); applyMatrix(inBitmap, result, matrix); return result; }
boolean isExifOrientationRequired = TransformationUtils.isExifOrientationRequired(orientation);
/** * Rotate and/or flip the image to match the given exif orientation. * * @param pool A pool that may or may not contain an image of the necessary * dimensions. * @param inBitmap The bitmap to rotate/flip. * @param exifOrientation the exif orientation [1-8]. * @return The rotated and/or flipped image or toOrient if no rotation or flip was necessary. */ public static Bitmap rotateImageExif(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int exifOrientation) { if (!isExifOrientationRequired(exifOrientation)) { return inBitmap; } final Matrix matrix = new Matrix(); initializeMatrixForRotation(exifOrientation, matrix); // From Bitmap.createBitmap. final RectF newRect = new RectF(0, 0, inBitmap.getWidth(), inBitmap.getHeight()); matrix.mapRect(newRect); final int newWidth = Math.round(newRect.width()); final int newHeight = Math.round(newRect.height()); Bitmap.Config config = getSafeConfig(inBitmap); Bitmap result = pool.get(newWidth, newHeight, config); matrix.postTranslate(-newRect.left, -newRect.top); applyMatrix(inBitmap, result, matrix); return result; }
boolean isExifOrientationRequired = TransformationUtils.isExifOrientationRequired(orientation);