Useful Glide transformations for use with the Android Glide image loading library.
Android development environment with the jcenter repository added in the project's build.gradle file. A target SDK of 14 or higher.
repositories {
jcenter()
}
Add the following dependency in the app's build.gradle file:
dependencies {
implementation 'net.scarlettsystems.android:glide:0.1.0'
}
Transformations can be passed into Glide using standard methods:
Glide.with(this)
.load(R.drawable.image)
.apply(new RequestOptions().transform(new Ellipse(this)))
.into(imageView);
Or multiple transformations at once:
Glide.with(this)
.load(R.drawable.image)
.apply(new RequestOptions().transforms(
new Ellipse(this),
new Mosaic(this).setByWidth(10),
new Greyscale(this)
))
.into(imageView);
Some transformations have parameters that can be set with a builder pattern:
Transformation t = new Shadow(this).setBlurRadius(10).setElevation(10).setAngle(45);
- Glide processes transformations in the order they are given as parameters to the
transforms()
function. It is important to consider the application order to achieve your desired effect. For instance, applying a cropping transformation (e.g.Padding()
orEllipse()
) beforeGaussianBlur()
will blur the newly drawn edges as well. It may be desired to apply a crop afterwards in order to preserve sharp image boundaries. - It is advised to perform image scaling through Glide's own transformations such as
CenterCrop()
andFitCenter()
before any other transformations rather than specifying ascaleType
in theImageView
's XML. Not only is it faster, but transformations do not know the final scaling mode and cannot adjust the transformation accordingly. Processing the scaling in XML may have undesired interactions with the transformations.
Current version: 0.1.0
- Shane Scarlett - core development - Scarlett Systems
This project is licensed under the Apache 2.0 License.