Java tutorial
//package com.java2s; import android.graphics.Bitmap; public class Main { public static Bitmap crop(Bitmap bitmap, int x, int y, int width, int height, boolean recycle) throws OutOfMemoryError { Bitmap output = Bitmap.createBitmap(bitmap, x, y, width, height); if (recycle && bitmap != output) { bitmap.recycle(); } return output; } }