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

java.lang.Object
  extended by com.bumptech.glide.load.resource.bitmap.BitmapTransformation
All Implemented Interfaces:
Transformation<Bitmap>
Direct Known Subclasses:
CenterCrop, FitCenter

public abstract class BitmapTransformation
extends Object
implements Transformation<Bitmap>

A simple Transformation for transforming Bitmaps that abstracts away dealing with Resource objects for subclasses. Use cases will look something like this:

 
 public class FillSpace extends BaseBitmapTransformation {
     @Override
     public Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
         if (toTransform.getWidth() == outWidth && toTransform.getHeight == outHeight) {
             return toTransform;
         }

         return Bitmap.createScaledBitmap(toTransform, outWidth, outHeight, true);
     }
 }
 
 


Constructor Summary
BitmapTransformation(BitmapPool bitmapPool)
           
BitmapTransformation(Context context)
           
 
Method Summary
protected abstract  Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight)
          Transforms the given Bitmap based on the given dimensions and returns the transformed result.
 Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight)
          Transforms the given resource and returns the transformed resource.
 
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.Transformation
getId
 

Constructor Detail

BitmapTransformation

public BitmapTransformation(Context context)

BitmapTransformation

public BitmapTransformation(BitmapPool bitmapPool)
Method Detail

transform

public final Resource<Bitmap> transform(Resource<Bitmap> resource,
                                        int outWidth,
                                        int outHeight)
Description copied from interface: Transformation
Transforms the given resource and returns the transformed resource.

Note - Transformations should be idempotent so if given a resource that has already been transformed by this transformation, this method must return the given resource object.

Note - If the original resource object is not returned, the original resource will be recycled and it's internal resources may be reused. This means it is not safe to rely on the original resource or any internal state of the original resource in any new resource that is created. Usually this shouldn't occur, but if absolutely necessary either the original resource object can be returned with modified internal state, or the data in the original resource can be copied into the transformed resource.

Specified by:
transform in interface Transformation<Bitmap>
Parameters:
resource - The resource to transform.
outWidth - The width of the view or target the resource will be displayed in.
outHeight - The height of the view or target the resource will be displayed in.
Returns:
The transformed resource.

transform

protected abstract Bitmap transform(BitmapPool pool,
                                    Bitmap toTransform,
                                    int outWidth,
                                    int outHeight)
Transforms the given Bitmap based on the given dimensions and returns the transformed result.

Note - As with all Transformations, this method must be idempotent. Given bitmap A, and bitmap B == transform(A). transform(B) must always equal B.

Parameters:
pool - A BitmapPool that can be used to obtain and return intermediate Bitmaps used in this transformation. For every Bitmap obtained from the pool during this transformation, a Bitmap must also be returned.
toTransform - The Bitmap to transform.
outWidth - The ideal width of the transformed bitmap (does not need to match exactly).
outHeight - The ideal height of the transformed bitmap (does not need to match exactly).