Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.util.Log; public class Main { public static Bitmap getCanvasBitmap(Bitmap bm, int width, int height) { int w = bm.getWidth(); int h = bm.getHeight(); if (w < width || h < height) { Log.e("bitmaputils", "bitmap target size is not "); return bm; } Bitmap bitmap = Bitmap.createBitmap(bm, (w - width) / 2, (h - height) / 2, width, height); return bitmap; } }