Created
September 13, 2017 07:33
-
-
Save alexzaitsev/0c16fdffa7c966aa822e41955eee5a0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void loadAndCropImage(Context context, @DrawableRes int resourceId, final int smallerSize, ImageView imageView) { | |
RequestOptions transformation = RequestOptions.bitmapTransform(new Transformation<Bitmap>() { | |
@Override | |
public Resource<Bitmap> transform(Context context, Resource<Bitmap> resource, int outWidth, int outHeight) { | |
BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); | |
Bitmap toTransform = resource.get(); | |
Bitmap transformed = TransformationUtils.centerCrop(bitmapPool, toTransform, smallerSize, smallerSize); | |
final Resource<Bitmap> result; | |
if (toTransform.equals(transformed)) { | |
result = resource; | |
} else { | |
result = BitmapResource.obtain(transformed, bitmapPool); | |
} | |
return result; | |
} | |
@Override | |
public void updateDiskCacheKey(MessageDigest messageDigest) { | |
messageDigest.update("crop transformation".getBytes()); | |
} | |
}); | |
Glide.with(context) | |
.load(resourceId) | |
.apply(transformation) | |
.into(imageView); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment