Class TransformationUtils
- java.lang.Object
-
- com.bumptech.glide.load.resource.bitmap.TransformationUtils
-
public final class TransformationUtils extends java.lang.ObjectA class with methods to efficiently resize Bitmaps.
-
-
Field Summary
Fields Modifier and Type Field Description static intPAINT_FLAGS
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static android.graphics.BitmapcenterCrop(BitmapPool pool, android.graphics.Bitmap inBitmap, int width, int height)A potentially expensive operation to crop the given Bitmap so that it fills the given dimensions.static android.graphics.BitmapcenterInside(BitmapPool pool, android.graphics.Bitmap inBitmap, int width, int height)If the Bitmap is smaller or equal to the Target it returns the original size, if not thenfitCenter(BitmapPool, Bitmap, int, int)is called instead.static android.graphics.BitmapcircleCrop(BitmapPool pool, android.graphics.Bitmap inBitmap, int destWidth, int destHeight)Crop the image to a circle and resize to the specified width/height.static android.graphics.BitmapfitCenter(BitmapPool pool, android.graphics.Bitmap inBitmap, int width, int height)An expensive operation to resize the given Bitmap down so that it fits within the given dimensions maintain the original proportions.static java.util.concurrent.locks.LockgetBitmapDrawableLock()static intgetExifOrientationDegrees(int exifOrientation)Get the # of degrees an image must be rotated to match the given exif orientation.static booleanisExifOrientationRequired(int exifOrientation)Returnstrueif the given exif orientation indicates that a transformation is necessary andfalseotherwise.static android.graphics.BitmaprotateImage(android.graphics.Bitmap imageToOrient, int degreesToRotate)This is an expensive operation that copies the image in place with the pixels rotated.static android.graphics.BitmaprotateImageExif(BitmapPool pool, android.graphics.Bitmap inBitmap, int exifOrientation)Rotate and/or flip the image to match the given exif orientation.static android.graphics.BitmaproundedCorners(BitmapPool pool, android.graphics.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.static android.graphics.BitmaproundedCorners(BitmapPool pool, android.graphics.Bitmap inBitmap, int roundingRadius)Creates a bitmap from a source bitmap and rounds the corners.static android.graphics.BitmaproundedCorners(BitmapPool pool, android.graphics.Bitmap inBitmap, int width, int height, int roundingRadius)Deprecated.Width and height are unused and ignored.static voidsetAlpha(android.graphics.Bitmap inBitmap, android.graphics.Bitmap outBitmap)Sets the alpha of the Bitmap we're going to re-use to the alpha of the Bitmap we're going to transform.
-
-
-
Field Detail
-
PAINT_FLAGS
public static final int PAINT_FLAGS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBitmapDrawableLock
public static java.util.concurrent.locks.Lock getBitmapDrawableLock()
-
centerCrop
public static android.graphics.Bitmap centerCrop(@NonNull BitmapPool pool, @NonNull android.graphics.Bitmap inBitmap, int width, int height)A potentially expensive operation to crop the given Bitmap so that it fills the given dimensions. This operation is significantly less expensive in terms of memory if a mutable Bitmap 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.- Returns:
- The resized Bitmap (will be recycled if recycled is not null).
-
fitCenter
public static android.graphics.Bitmap fitCenter(@NonNull BitmapPool pool, @NonNull android.graphics.Bitmap inBitmap, int width, int height)An expensive operation to resize the given Bitmap down so that it fits within the given dimensions 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.- Returns:
- A new Bitmap shrunk to fit within the given dimensions, or toFit if toFit's width or height matches the given dimensions and toFit fits within the given dimensions
-
centerInside
public static android.graphics.Bitmap centerInside(@NonNull BitmapPool pool, @NonNull android.graphics.Bitmap inBitmap, int width, int height)If the Bitmap is smaller or equal to the Target it returns the original size, if not thenfitCenter(BitmapPool, Bitmap, int, int)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.- Returns:
- returns input Bitmap if smaller or equal to target, or toFit if the Bitmap's width or height is larger than the given dimensions
-
setAlpha
public static void setAlpha(android.graphics.Bitmap inBitmap, android.graphics.Bitmap outBitmap)Sets the alpha of the Bitmap we're going to re-use to the alpha of the Bitmap we're going to transform. This keepsBitmap.hasAlpha()} consistent before and after the transformation for transformations that don't add or remove transparent pixels.- Parameters:
inBitmap- TheBitmapthat will be transformed.outBitmap- TheBitmapthat will be returned from the transformation.
-
rotateImage
public static android.graphics.Bitmap rotateImage(@NonNull android.graphics.Bitmap imageToOrient, int degreesToRotate)This is an expensive operation that copies the image in place with the pixels rotated. If possible 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. If zero the original image is returned unmodified.- Returns:
- The oriented bitmap. May be the imageToOrient without modification, or a new Bitmap.
-
getExifOrientationDegrees
public 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]- Returns:
- the number of degrees to rotate
-
rotateImageExif
public static android.graphics.Bitmap rotateImageExif(@NonNull BitmapPool pool, @NonNull android.graphics.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].- Returns:
- The rotated and/or flipped image or toOrient if no rotation or flip was necessary.
-
isExifOrientationRequired
public static boolean isExifOrientationRequired(int exifOrientation)
Returnstrueif the given exif orientation indicates that a transformation is necessary andfalseotherwise.
-
circleCrop
public static android.graphics.Bitmap circleCrop(@NonNull BitmapPool pool, @NonNull android.graphics.Bitmap inBitmap, int destWidth, int destHeight)Crop the image to a circle and resize to the specified width/height. The circle crop will have the 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.- Returns:
- The resized Bitmap (will be recycled if recycled is not null).
-
roundedCorners
@Deprecated public static android.graphics.Bitmap roundedCorners(@NonNull BitmapPool pool, @NonNull android.graphics.Bitmap inBitmap, int width, int height, int roundingRadius)Deprecated.Width and height are unused and ignored. UseroundedCorners(BitmapPool, Bitmap, int)instead.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).- Returns:
- a
Bitmapsimilar to inBitmap but with rounded corners. - Throws:
java.lang.IllegalArgumentException- if roundingRadius, width or height is 0 or less.
-
roundedCorners
public static android.graphics.Bitmap roundedCorners(@NonNull BitmapPool pool, @NonNull android.graphics.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, considerBaseRequestOptions.transform(Transformation[])and/orMultiTransformation.- 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).- Returns:
- a
Bitmapsimilar to inBitmap but with rounded corners. - Throws:
java.lang.IllegalArgumentException- if roundingRadius, width or height is 0 or less.
-
roundedCorners
public static android.graphics.Bitmap roundedCorners(@NonNull BitmapPool pool, @NonNull android.graphics.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, considerBaseRequestOptions.transform(Transformation[])and/orMultiTransformation.- 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- Returns:
- a
Bitmapsimilar to inBitmap but with rounded corners.
-
-