Here you can find the source of cropCenter(Bitmap bitmap, boolean recycle)
public static Bitmap cropCenter(Bitmap bitmap, boolean recycle)
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; public class Main { public static Bitmap cropCenter(Bitmap bitmap, boolean recycle) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (width == height) return bitmap; int size = Math.min(width, height); Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap)); Canvas canvas = new Canvas(target); canvas.translate((size - width) / 2, (size - height) / 2); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bitmap, 0, 0, paint); if (recycle) bitmap.recycle();/* ww w.ja v a 2s .com*/ return target; } private static Bitmap.Config getConfig(Bitmap bitmap) { Bitmap.Config config = bitmap.getConfig(); if (config == null) { config = Bitmap.Config.ARGB_8888; } return config; } }