BitmapTransformation
A simple com.bumptech.glide.load.Transformation for transforming s that abstracts away dealing with objects for subclasses.
Use cases will look something like this:
public class FillSpace extends BitmapTransformation {
private static final String ID = "com.bumptech.glide.transformations.FillSpace";
private static final byte[] ID_BYTES = ID.getBytes(Charset.forName("UTF-8"));
{@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);
}
{@Override}
public boolean equals(Object o) {
return o instanceof FillSpace;
}
{@Override}
public int hashCode() {
return ID.hashCode();
}
{@Override}
public void updateDiskCacheKey(MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
}
}
Using the fully qualified class name as a static final String (not getName to avoid proguard obfuscation) is an easy way to implement updateDiskCacheKey} correctly. If additional arguments are required they can be passed in to the constructor of the Transformation
and then used to update the java.security.MessageDigest passed in to updateDiskCacheKey. If arguments are primitive types, they can typically easily be serialized using java.nio.ByteBuffer. String types can be serialized with getBytes using the constant CHARSET.
As with all Transformations, all subclasses must implement equals and hashCode for memory caching to work correctly.