Here you can find the source of createCenterCropBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
public static Bitmap createCenterCropBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
//package com.java2s; import android.graphics.Bitmap; public class Main { public static Bitmap createCenterCropBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource) { if (srcBitmap == null || dstWidth == 0 || dstHeight == 0) { return srcBitmap; }/*from w w w . j a v a2 s .c o m*/ int srcWidth = srcBitmap.getWidth(); int srcHeight = srcBitmap.getHeight(); Bitmap dstBitmap = srcBitmap; try { if ((dstHeight / dstWidth) - (srcHeight / srcWidth) > 0) { int newWidth = (srcHeight * dstWidth) / dstHeight; dstBitmap = Bitmap.createBitmap(srcBitmap, (srcWidth - newWidth) / 2, 0, newWidth, srcHeight); } else { int newHeight = (dstHeight * srcWidth) / dstWidth; dstBitmap = Bitmap.createBitmap(srcBitmap, 0, (srcHeight - newHeight) / 2, srcWidth, newHeight); } if (dstBitmap != srcBitmap && tryRecycleSource) { srcBitmap.recycle(); } } catch (Throwable e) { e.printStackTrace(); } return dstBitmap; } }