Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.*; public class Main { public static final Bitmap newBitmapSquareCenterCrop(Bitmap bitmap) { if (bitmap == null) { return null; } int width = bitmap.getWidth(); int height = bitmap.getHeight(); int left, top, right, bottom; if (width < height) { int cropSize = width; left = 0; right = cropSize; top = height / 2 - cropSize / 2; bottom = top + cropSize; } else { int cropSize = height; top = 0; bottom = cropSize; left = width / 2 - cropSize / 2; right = left + cropSize; } return Bitmap.createBitmap(bitmap, left, top, right - left, bottom - top); } }