Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Bitmap; public class Main { private static Bitmap bitmapCrop(Bitmap rawBitmap, int width, int height, int resWidth, int resHeight) { int cropX, cropY, cropWidth, cropHeight; float xScale = (float) width / (float) resWidth; float yScale = (float) height / (float) resHeight; float scale = Math.max(xScale, yScale); if (xScale >= yScale) { cropWidth = Math.round(resWidth); cropX = 0; cropHeight = Math.round(height / scale); cropY = (resHeight - cropHeight) / 2; } else { cropWidth = Math.round(width / scale); cropX = (resWidth - cropWidth) / 2; cropHeight = Math.round(resHeight); cropY = 0; } return Bitmap.createBitmap(rawBitmap, cropX, cropY, cropWidth, cropHeight); } }