com.bumptech.glide.resize.load
Class Downsampler

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

public abstract class Downsampler
extends java.lang.Object

A base class with methods for loading and decoding images from InputStreams.


Field Summary
static Downsampler AT_LEAST
          Load and scale the image uniformly (maintaining the image's aspect ratio) so that the dimensions of the image will be greater than or equal to the given width and height.
static Downsampler AT_MOST
          Load and scale the image uniformly (maintaining the image's aspect ratio) so that the dimensions of the image will be less than or equal to the given width and height.
static Downsampler NONE
          Load the image at its original size
 
Constructor Summary
Downsampler()
           
 
Method Summary
 android.graphics.Bitmap downsample(RecyclableBufferedInputStream bis, android.graphics.BitmapFactory.Options options, BitmapPool pool, int outWidth, int outHeight)
          Load the image for the given InputStream.
protected  android.graphics.Bitmap downsampleWithSize(RecyclableBufferedInputStream bis, android.graphics.BitmapFactory.Options options, BitmapPool pool, int inWidth, int inHeight, int sampleSize)
           
 int[] getDimensions(RecyclableBufferedInputStream bis, android.graphics.BitmapFactory.Options options)
          A method for getting the dimensions of an image from the given InputStream
 java.lang.String getId()
          Get some id that uniquely identifies the downsample for use as part of a cache key
protected abstract  int getSampleSize(int inWidth, int inHeight, int outWidth, int outHeight)
          Determine the amount of downsampling to use for a load given the dimensions of the image to be downsampled and the dimensions of the view/target the image will be displayed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AT_LEAST

public static Downsampler AT_LEAST
Load and scale the image uniformly (maintaining the image's aspect ratio) so that the dimensions of the image will be greater than or equal to the given width and height.


AT_MOST

public static Downsampler AT_MOST
Load and scale the image uniformly (maintaining the image's aspect ratio) so that the dimensions of the image will be less than or equal to the given width and height.


NONE

public static Downsampler NONE
Load the image at its original size

Constructor Detail

Downsampler

public Downsampler()
Method Detail

downsample

public android.graphics.Bitmap downsample(RecyclableBufferedInputStream bis,
                                          android.graphics.BitmapFactory.Options options,
                                          BitmapPool pool,
                                          int outWidth,
                                          int outHeight)
Load the image for the given InputStream. If a recycled Bitmap whose dimensions exactly match those of the image for the given InputStream is available, the operation is much less expensive in terms of memory. Note - this method will throw an exception of a Bitmap with dimensions not matching those of the image for the given InputStream is provided.

Parameters:
bis - An InputStream to the data for the image
options - The options to pass to BitmapFactory.decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options)
pool - A pool of recycled bitmaps
outWidth - The width the final image should be close to
outHeight - The height the final image should be close to
Returns:
A new bitmap containing the image from the given InputStream, or recycle if recycle is not null

downsampleWithSize

protected android.graphics.Bitmap downsampleWithSize(RecyclableBufferedInputStream bis,
                                                     android.graphics.BitmapFactory.Options options,
                                                     BitmapPool pool,
                                                     int inWidth,
                                                     int inHeight,
                                                     int sampleSize)

getId

public java.lang.String getId()
Get some id that uniquely identifies the downsample for use as part of a cache key

Returns:
A unique String

getSampleSize

protected abstract int getSampleSize(int inWidth,
                                     int inHeight,
                                     int outWidth,
                                     int outHeight)
Determine the amount of downsampling to use for a load given the dimensions of the image to be downsampled and the dimensions of the view/target the image will be displayed in.

Parameters:
inWidth - The width of the image to be downsampled
inHeight - The height of the image to be downsampled
outWidth - The width of the view/target the image will be displayed in
outHeight - The height of the view/target the imag will be displayed in
Returns:
An integer to pass in to BitmapFactory.decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options)
See Also:
BitmapFactory.Options#inSampleSize

getDimensions

public int[] getDimensions(RecyclableBufferedInputStream bis,
                           android.graphics.BitmapFactory.Options options)
A method for getting the dimensions of an image from the given InputStream

Parameters:
bis - The InputStream representing the image
options - The options to pass to BitmapFactory.decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options)
Returns:
an array containing the dimensions of the image in the form {width, height}