Here you can find the source of createFitCenterBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
public static Bitmap createFitCenterBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
//package com.java2s; import android.graphics.Bitmap; public class Main { public static Bitmap createFitCenterBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource) { if (srcBitmap == null || dstWidth <= 0 || dstHeight <= 0) { return srcBitmap; }//from w ww.j a va 2 s . com int srcWidth = srcBitmap.getWidth(); int srcHeight = srcBitmap.getHeight(); int newWidth = srcWidth; int newHeight = srcHeight; if (newWidth > dstWidth) { newHeight = dstWidth * newHeight / newWidth; newWidth = dstWidth; } if (newHeight > dstHeight) { newWidth = dstHeight * newWidth / newHeight; newHeight = dstHeight; } return createFitXYBitmap(srcBitmap, newWidth, newHeight, tryRecycleSource); } public static Bitmap createFitXYBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource) { if (srcBitmap == null || dstWidth <= 0 || dstHeight <= 0) { return srcBitmap; } Bitmap dstBitmap = srcBitmap; try { dstBitmap = Bitmap.createScaledBitmap(srcBitmap, dstWidth, dstHeight, true); if (dstBitmap != srcBitmap && tryRecycleSource) { srcBitmap.recycle(); } } catch (Throwable e) { e.printStackTrace(); } return dstBitmap; } }