Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Canvas; public class Main { public static Bitmap addPadding(Bitmap bmp, int color) { if (bmp == null) { return null; } int biggerParam = Math.max(bmp.getWidth(), bmp.getHeight()); Bitmap bitmap = Bitmap.createBitmap(biggerParam, biggerParam, bmp.getConfig()); Canvas canvas = new Canvas(bitmap); canvas.drawColor(color); int top = bmp.getHeight() > bmp.getWidth() ? 0 : (bmp.getWidth() - bmp.getHeight()) / 2; int left = bmp.getWidth() > bmp.getHeight() ? 0 : (bmp.getHeight() - bmp.getWidth()) / 2; canvas.drawBitmap(bmp, left, top, null); return bitmap; } }