com.bumptech.glide.resize.load
Class ImageResizer

java.lang.Object
  extended by com.bumptech.glide.resize.load.ImageResizer

public class ImageResizer
extends java.lang.Object

A class for synchronously resizing bitmaps with or without Bitmaps to reuse


Field Summary
static int PAINT_FLAGS
           
 
Constructor Summary
ImageResizer()
          Creates a new resizer that will not recycle Bitmaps
ImageResizer(android.graphics.BitmapFactory.Options options)
          Deprecated. 
ImageResizer(BitmapPool bitmapPool)
           
ImageResizer(BitmapPool bitmapPool, android.graphics.BitmapFactory.Options defaultOptions)
          Deprecated. 
 
Method Summary
static android.graphics.Bitmap centerCrop(android.graphics.Bitmap recycled, android.graphics.Bitmap toCrop, int width, int height)
          A potentially expensive operation to crop the given Bitmap so that it fills the given dimensions.
static android.graphics.Bitmap fitCenter(android.graphics.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 android.graphics.Bitmap fitInSpace(android.graphics.Bitmap toFit, int width, int height)
          Deprecated. 
static android.graphics.BitmapFactory.Options getDefaultOptions()
           
static int getExifOrientationDegrees(int exifOrientation)
          Get the # of degrees an image must be rotated to match the given exif orientation.
static int getOrientation(java.lang.String pathToOriginal)
          Returns a matrix with rotation set based on Exif orientation tag.
 android.graphics.Bitmap load(java.io.InputStream is)
           
 android.graphics.Bitmap load(java.io.InputStream is, int outWidth, int outHeight)
           
 android.graphics.Bitmap load(java.io.InputStream is, int outWidth, int outHeight, Downsampler downsampler)
           
 android.graphics.Bitmap load(java.io.InputStream is, int outWidth, int outHeight, Downsampler downsampler, Transformation transformation)
           
 android.graphics.Bitmap load(java.io.InputStream is, int outWidth, int outHeight, Transformation transformation)
           
static android.graphics.Bitmap orientImage(java.lang.String pathToOriginal, android.graphics.Bitmap imageToOrient)
          This is an expensive operation that copies the image in place with the pixels rotated.
static android.graphics.Bitmap rotateImage(android.graphics.Bitmap imageToOrient, int degreesToRotate)
          This is an expensive operation that copies the image in place with the pixels rotated.
static android.graphics.Bitmap rotateImageExif(android.graphics.Bitmap toOrient, BitmapPool pool, int exifOrientation)
          Rotate and/or flip the image to match the given exif orientation
static android.graphics.Bitmap shrinkToHeight(android.graphics.Bitmap toShrink, int height)
          An expensive operation to resize the given image, maintaining the original proportions, so that its height matches the given height
static android.graphics.Bitmap shrinkToWidth(android.graphics.Bitmap toShrink, int width)
          An expensive operation to resize the given image, maintaining the original proportions, so that its width matches the given width
 
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
Constructor Detail

ImageResizer

public ImageResizer()
Creates a new resizer that will not recycle Bitmaps


ImageResizer

public ImageResizer(BitmapPool bitmapPool)

ImageResizer

@Deprecated
public ImageResizer(android.graphics.BitmapFactory.Options options)
Deprecated. 


ImageResizer

@Deprecated
public ImageResizer(BitmapPool bitmapPool,
                               android.graphics.BitmapFactory.Options defaultOptions)
Deprecated. 

Creates a new resizer that will attempt to recycle Bitmaps if any are available in the given dimensions

Parameters:
bitmapPool - The cache to try to recycle Bitmaps from
Method Detail

getDefaultOptions

public static android.graphics.BitmapFactory.Options getDefaultOptions()

load

public android.graphics.Bitmap load(java.io.InputStream is)

load

public android.graphics.Bitmap load(java.io.InputStream is,
                                    int outWidth,
                                    int outHeight)

load

public android.graphics.Bitmap load(java.io.InputStream is,
                                    int outWidth,
                                    int outHeight,
                                    Transformation transformation)

load

public android.graphics.Bitmap load(java.io.InputStream is,
                                    int outWidth,
                                    int outHeight,
                                    Downsampler downsampler)

load

public android.graphics.Bitmap load(java.io.InputStream is,
                                    int outWidth,
                                    int outHeight,
                                    Downsampler downsampler,
                                    Transformation transformation)

centerCrop

public static android.graphics.Bitmap centerCrop(android.graphics.Bitmap recycled,
                                                 android.graphics.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 of the final Bitmap
height - The height of the final Bitmap
Returns:
The resized Bitmap (will be recycled if recycled is not null)

shrinkToWidth

public static android.graphics.Bitmap shrinkToWidth(android.graphics.Bitmap toShrink,
                                                    int width)
An expensive operation to resize the given image, maintaining the original proportions, so that its width matches the given width

Parameters:
toShrink - The Bitmap to shrink
width - The width of the final Bitmap
Returns:
A new Bitmap shrunk to the given width, or toShrink if toShrink's width is equivalent to the given width

shrinkToHeight

public static android.graphics.Bitmap shrinkToHeight(android.graphics.Bitmap toShrink,
                                                     int height)
An expensive operation to resize the given image, maintaining the original proportions, so that its height matches the given height

Parameters:
toShrink - The Bitmap to shrink
height - The height of the final Bitmap
Returns:
A new Bitmap shrunk to the given height, or toShrink if toShink's height is equivalent to the given height

fitInSpace

@Deprecated
public static android.graphics.Bitmap fitInSpace(android.graphics.Bitmap toFit,
                                                            int width,
                                                            int height)
Deprecated. 

An expensive operation to resize the given Bitmap down so that it fits within the given dimensions maintaining the original proportions

Parameters:
toFit - The Bitmap to shrink
width - The width the final image will fit within
height - The height 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

fitCenter

public static android.graphics.Bitmap fitCenter(android.graphics.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 the final image will fit within.
height - The height 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

getOrientation

public static int getOrientation(java.lang.String pathToOriginal)
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

public static android.graphics.Bitmap orientImage(java.lang.String pathToOriginal,
                                                  android.graphics.Bitmap imageToOrient)
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 android.graphics.Bitmap rotateImage(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 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 android.graphics.Bitmap rotateImageExif(android.graphics.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