Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Matrix; public class Main { /** * @param bitmap * @param matrix * @return * Function to get a square image once cropped from a rectangular image.. */ public static Bitmap getSquareImage(Bitmap bitmap, Matrix matrix) { if (bitmap.getWidth() >= bitmap.getHeight()) { return Bitmap.createBitmap(bitmap, bitmap.getWidth() / 2 - bitmap.getHeight() / 2, 0, bitmap.getHeight(), bitmap.getHeight(), matrix, false); } else { return Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 2 - bitmap.getWidth() / 2, bitmap.getWidth(), bitmap.getWidth(), matrix, false); } } }