Equivalent of ImageView scaleType ‘centerCrop’ to bitmap drawable gravity

To center crop a bitmap in code do this:

public static Bitmap cropCenter(Bitmap bmp) {
    int dimension = Math.min(bmp.getWidth(), bmp.getHeight());
    return ThumbnailUtils.extractThumbnail(bmp, dimension, dimension);
}

I don’t know of any other way to centerCrop a bitmap xml wise.

Hope it helps anyone.

I found this solution from this post:
Android Crop Center of Bitmap

Leave a Comment