Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Bitmap; public class Main { public static Bitmap resizeBitmap(Bitmap image, int maxSize) { int width = image.getWidth(); int height = image.getHeight(); float aspectRatio = width / (float) height; if (aspectRatio > 1) { width = maxSize; height = Math.round(width / aspectRatio); } else { height = maxSize; width = Math.round(height * aspectRatio); } return Bitmap.createScaledBitmap(image, width, height, true); } }