Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Matrix; public class Main { static Bitmap resizeBitmap(Bitmap bitmap, int maximumDimension, boolean scaleUpIfSmaller) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float newScale; if (Math.max(width, height) <= maximumDimension && !scaleUpIfSmaller) { return bitmap; } if (width > height) { newScale = (float) maximumDimension / (float) width; } else { newScale = (float) maximumDimension / (float) height; } Matrix matrix = new Matrix(); matrix.postScale(newScale, newScale); return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); } }