Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.support.annotation.NonNull; public class Main { public static Bitmap addPadding(@NonNull Bitmap bmp) { int biggerParam = Math.max(bmp.getWidth(), bmp.getHeight()); Bitmap bitmap = Bitmap.createBitmap(biggerParam, biggerParam, bmp.getConfig()); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); 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; } }