BitmapTransformation

abstract class BitmapTransformation : Transformation<T>

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.

Functions

Link copied to clipboard
abstract fun equals(o: Any): Boolean
For caching to work correctly, implementations must implement this method and hashCode.
Link copied to clipboard
abstract fun hashCode(): Int
For caching to work correctly, implementations must implement this method and equals.
Link copied to clipboard
fun transform(    context: Context,     resource: Resource<Bitmap>,     outWidth: Int,     outHeight: Int): Resource<Bitmap>
Transforms the given resource and returns the transformed resource.
Link copied to clipboard
abstract fun updateDiskCacheKey(messageDigest: MessageDigest)
Adds all uniquely identifying information to the given digest.

Properties

Link copied to clipboard
val CHARSET: Charset
Link copied to clipboard
val STRING_CHARSET_NAME: String

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard