-
public final class TransformationUtilsA class with methods to efficiently resize Bitmaps.
-
-
Field Summary
Fields Modifier and Type Field Description public final static intPAINT_FLAGS
-
Method Summary
Modifier and Type Method Description static LockgetBitmapDrawableLock()static BitmapcenterCrop(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height)A potentially expensive operation to crop the given Bitmap so that it fills the givendimensions. static BitmapfitCenter(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height)An expensive operation to resize the given Bitmap down so that it fits within the givendimensions maintain the original proportions. static BitmapcenterInside(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height)If the Bitmap is smaller or equal to the Target it returns the original size, if not then fitCenter is called instead. static voidsetAlpha(Bitmap inBitmap, Bitmap outBitmap)Sets the alpha of the Bitmap we're going to re-use to the alpha of the Bitmap we're going totransform. static BitmaprotateImage(@NonNull() Bitmap imageToOrient, int degreesToRotate)This is an expensive operation that copies the image in place with the pixels rotated. static intgetExifOrientationDegrees(int exifOrientation)Get the # of degrees an image must be rotated to match the given exif orientation. static BitmaprotateImageExif(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int exifOrientation)Rotate and/or flip the image to match the given exif orientation. static booleanisExifOrientationRequired(int exifOrientation)Returns {@code true}if the given exif orientation indicates that a transformation is necessaryand{@code false}otherwise.static BitmapcircleCrop(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int destWidth, int destHeight)Crop the image to a circle and resize to the specified width/height. static BitmaproundedCorners(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height, int roundingRadius)Creates a bitmap from a source bitmap and rounds the corners. static BitmaproundedCorners(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int roundingRadius)Creates a bitmap from a source bitmap and rounds the corners. static BitmaproundedCorners(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, float topLeft, float topRight, float bottomRight, float bottomLeft)Creates a bitmap from a source bitmap and rounds the corners, applying a potentially different[X, Y] radius to each corner. -
-
Method Detail
-
getBitmapDrawableLock
static Lock getBitmapDrawableLock()
-
centerCrop
static Bitmap centerCrop(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height)
A potentially expensive operation to crop the given Bitmap so that it fills the givendimensions. This operation is significantly less expensive in terms of memory if a mutableBitmap with the given dimensions is passed in as well.
- Parameters:
pool- The BitmapPool to obtain a bitmap from.inBitmap- The Bitmap to resize.width- The width in pixels of the final Bitmap.height- The height in pixels of the final Bitmap.
-
fitCenter
static Bitmap fitCenter(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height)
An expensive operation to resize the given Bitmap down so that it fits within the givendimensions maintain the original proportions.
- Parameters:
pool- The BitmapPool obtain a bitmap from.inBitmap- The Bitmap to shrink.width- The width in pixels the final image will fit within.height- The height in pixels the final image will fit within.
-
centerInside
static Bitmap centerInside(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height)
If the Bitmap is smaller or equal to the Target it returns the original size, if not then fitCenter is called instead.
- Parameters:
pool- The BitmapPool obtain a bitmap from.inBitmap- The Bitmap to center.width- The width in pixels of the target.height- The height in pixels of the target.
-
setAlpha
static void setAlpha(Bitmap inBitmap, Bitmap outBitmap)
Sets the alpha of the Bitmap we're going to re-use to the alpha of the Bitmap we're going totransform. This keeps hasAlpha} consistent before and afterthe transformation for transformations that don't add or remove transparent pixels.
-
rotateImage
static Bitmap rotateImage(@NonNull() Bitmap imageToOrient, int degreesToRotate)
This is an expensive operation that copies the image in place with the pixels rotated. Ifpossible rather use getOrientationMatrix, and put that as the imageMatrix on an ImageView.
- Parameters:
imageToOrient- Image Bitmap to orient.degreesToRotate- number of degrees to rotate the image by.
-
getExifOrientationDegrees
static int getExifOrientationDegrees(int exifOrientation)
Get the # of degrees an image must be rotated to match the given exif orientation.
- Parameters:
exifOrientation- The exif orientation [1-8]
-
rotateImageExif
static Bitmap rotateImageExif(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int exifOrientation)
Rotate and/or flip the image to match the given exif orientation.
- Parameters:
pool- A pool that may or may not contain an image of the necessary dimensions.inBitmap- The bitmap to rotate/flip.exifOrientation- the exif orientation [1-8].
-
isExifOrientationRequired
static boolean isExifOrientationRequired(int exifOrientation)
Returns
{@code true}if the given exif orientation indicates that a transformation is necessaryand{@code false}otherwise.
-
circleCrop
static Bitmap circleCrop(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int destWidth, int destHeight)
Crop the image to a circle and resize to the specified width/height. The circle crop will havethe same width and height equal to the min-edge of the result image.
- Parameters:
pool- The BitmapPool obtain a bitmap from.inBitmap- The Bitmap to resize.destWidth- The width in pixels of the final Bitmap.destHeight- The height in pixels of the final Bitmap.
-
roundedCorners
@Deprecated() static Bitmap roundedCorners(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int width, int height, int roundingRadius)
Creates a bitmap from a source bitmap and rounds the corners.
- Parameters:
inBitmap- the source bitmap to use as a basis for the created bitmap.width- the width of the generated bitmap.height- the height of the generated bitmap.roundingRadius- the corner radius to be applied (in device-specific pixels).
-
roundedCorners
static Bitmap roundedCorners(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, int roundingRadius)
Creates a bitmap from a source bitmap and rounds the corners.
This method does NOT resize the given Bitmap, it only rounds it's corners.To both resize and round the corners of an image, consider and/or .
- Parameters:
inBitmap- the source bitmap to use as a basis for the created bitmap.roundingRadius- the corner radius to be applied (in device-specific pixels).
-
roundedCorners
static Bitmap roundedCorners(@NonNull() BitmapPool pool, @NonNull() Bitmap inBitmap, float topLeft, float topRight, float bottomRight, float bottomLeft)
Creates a bitmap from a source bitmap and rounds the corners, applying a potentially different[X, Y] radius to each corner.
This method does NOT resize the given Bitmap, it only rounds it's corners.To both resize and round the corners of an image, consider and/or .
- Parameters:
inBitmap- the source bitmap to use as a basis for the created bitmap.topLeft- top-left radiustopRight- top-right radiusbottomRight- bottom-right radiusbottomLeft- bottom-left radius
-
-
-
-