1 package com.bumptech.glide.load.resource.bitmap; 2 3 import android.content.Context; 4 import android.graphics.Bitmap; 5 6 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 7 8 /** 9 * Scale the image so that either the width of the image matches the given width and the height of the image is 10 * greater than the given height or vice versa, and then crop the larger dimension to match the given dimension. 11 * 12 * Does not maintain the image's aspect ratio 13 */ 14 public class CenterCrop extends BitmapTransformation { 15 16 public CenterCrop(Context context) { 17 super(context); 18 } 19 20 public CenterCrop(BitmapPool bitmapPool) { 21 super(bitmapPool); 22 } 23 24 // Bitmap doesn't implement equals, so == and .equals are equivalent here. 25 @SuppressWarnings("PMD.CompareObjectsWithEquals") 26 @Override 27 protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { 28 final Bitmap toReuse = pool.get(outWidth, outHeight, toTransform.getConfig() != null 29 ? toTransform.getConfig() : Bitmap.Config.ARGB_8888); 30 Bitmap transformed = TransformationUtils.centerCrop(toReuse, toTransform, outWidth, outHeight); 31 if (toReuse != null && toReuse != transformed && !pool.put(toReuse)) { 32 toReuse.recycle(); 33 } 34 return transformed; 35 } 36 37 @Override 38 public String getId() { 39 return "CenterCrop.com.bumptech.glide.load.resource.bitmap"; 40 } 41 } 42