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

java.lang.Object
  extended by com.bumptech.glide.load.resource.bitmap.Downsampler
All Implemented Interfaces:
BitmapDecoder<InputStream>

public abstract class Downsampler
extends Object
implements BitmapDecoder<InputStream>

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 smallest edge of the image will be between 1x and 2x the requested size.
static Downsampler AT_MOST
          Load and scale the image uniformly (maintaining the image's aspect ratio) so that largest edge of the image will be between 1/2x and 1x of the requested size.
static Downsampler NONE
          Load the image at its original size.
 
Constructor Summary
Downsampler()
           
 
Method Summary
 Bitmap decode(InputStream is, BitmapPool pool, int outWidth, int outHeight, DecodeFormat decodeFormat)
          Load the image for the given InputStream.
 int[] getDimensions(MarkEnforcingInputStream is, RecyclableBufferedInputStream bufferedStream, BitmapFactory.Options options)
          A method for getting the dimensions of an image from the given InputStream.
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
 
Methods inherited from interface com.bumptech.glide.load.resource.bitmap.BitmapDecoder
getId
 

Field Detail

AT_LEAST

public static final Downsampler AT_LEAST
Load and scale the image uniformly (maintaining the image's aspect ratio) so that the smallest edge of the image will be between 1x and 2x the requested size. The larger edge has no maximum size.


AT_MOST

public static final Downsampler AT_MOST
Load and scale the image uniformly (maintaining the image's aspect ratio) so that largest edge of the image will be between 1/2x and 1x of the requested size. The smaller edge has no minimum size.


NONE

public static final Downsampler NONE
Load the image at its original size.

Constructor Detail

Downsampler

public Downsampler()
Method Detail

decode

public Bitmap decode(InputStream is,
                     BitmapPool pool,
                     int outWidth,
                     int outHeight,
                     DecodeFormat decodeFormat)
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.

Specified by:
decode in interface BitmapDecoder<InputStream>
Parameters:
is - An InputStream to the data for the image.
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.
decodeFormat - The desired configuration for the returned bitmap.
Returns:
A new bitmap containing the image from the given InputStream, or recycle if recycle is not null.

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 in pixels of the image to be downsampled.
inHeight - The height in piexels of the image to be downsampled.
outWidth - The width in pixels of the view/target the image will be displayed in.
outHeight - The height in pixels 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(MarkEnforcingInputStream is,
                           RecyclableBufferedInputStream bufferedStream,
                           BitmapFactory.Options options)
A method for getting the dimensions of an image from the given InputStream.

Parameters:
is - 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}.