com.bumptech.glide.load.resource.bitmap
Class TransformationUtils

java.lang.Object
  extended by com.bumptech.glide.load.resource.bitmap.TransformationUtils

public final class TransformationUtils
extends Object

A class with methods to efficiently resize Bitmaps.


Field Summary
static int PAINT_FLAGS
           
 
Method Summary
static Bitmap centerCrop(Bitmap recycled, Bitmap toCrop, int width, int height)
          A potentially expensive operation to crop the given Bitmap so that it fills the given dimensions.
static Bitmap fitCenter(Bitmap toFit, BitmapPool pool, 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 int getExifOrientationDegrees(int exifOrientation)
          Get the # of degrees an image must be rotated to match the given exif orientation.
static int getOrientation(String pathToOriginal)
          Deprecated. No longer used by Glide, scheduled to be removed in Glide 4.0
static Bitmap orientImage(String pathToOriginal, Bitmap imageToOrient)
          Deprecated. No longer used by Glide, scheduled to be removed in Glide 4.0
static Bitmap rotateImage(Bitmap imageToOrient, int degreesToRotate)
          This is an expensive operation that copies the image in place with the pixels rotated.
static Bitmap rotateImageExif(Bitmap toOrient, BitmapPool pool, int exifOrientation)
          Rotate and/or flip the image to match the given exif orientation.
static void setAlpha(Bitmap toTransform, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAINT_FLAGS

public static final int PAINT_FLAGS
See Also:
Constant Field Values
Method Detail

centerCrop

public static Bitmap centerCrop(Bitmap recycled,
                                Bitmap toCrop,
                                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:
recycled - A mutable Bitmap with dimensions width and height that we can load the cropped portion of toCrop into.
toCrop - 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 Bitmap fitCenter(Bitmap toFit,
                               BitmapPool pool,
                               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:
toFit - The Bitmap to shrink.
pool - The BitmapPool to try to reuse a bitmap from.
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

setAlpha

public static void setAlpha(Bitmap toTransform,
                            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 keeps Bitmap.hasAlpha()} consistent before and after the transformation for transformations that don't add or remove transparent pixels.

Parameters:
toTransform - The Bitmap that will be transformed.
outBitmap - The Bitmap that will be returned from the transformation.

getOrientation

@Deprecated
public static int getOrientation(String pathToOriginal)
Deprecated. No longer used by Glide, scheduled to be removed in Glide 4.0

Returns a matrix with rotation set based on Exif orientation tag. If the orientation is undefined or 0 null is returned.

Parameters:
pathToOriginal - Path to original image file that may have exif data.
Returns:
A rotation in degrees based on exif orientation

orientImage

@Deprecated
public static Bitmap orientImage(String pathToOriginal,
                                            Bitmap imageToOrient)
Deprecated. No longer used by Glide, scheduled to be removed in Glide 4.0

This is an expensive operation that copies the image in place with the pixels rotated. If possible rather use getOrientationMatrix, and set that as the imageMatrix on an ImageView.

Parameters:
pathToOriginal - Path to original image file that may have exif data.
imageToOrient - Image Bitmap to orient.
Returns:
The oriented bitmap. May be the imageToOrient without modification, or a new Bitmap.

rotateImage

public static Bitmap rotateImage(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 set 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 Bitmap rotateImageExif(Bitmap toOrient,
                                     BitmapPool pool,
                                     int exifOrientation)
Rotate and/or flip the image to match the given exif orientation.

Parameters:
toOrient - The bitmap to rotate/flip.
pool - A pool that may or may not contain an image of the necessary dimensions.
exifOrientation - the exif orientation [1-8].
Returns:
The rotated and/or flipped image or toOrient if no rotation or flip was necessary.