Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { public static Bitmap resizeBitmap(String photoPath, int maxSide) { BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(photoPath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; boolean landscape = true; if (photoW < photoH) { // portrait landscape = false; } int scaleFactor = 1; if (landscape) { scaleFactor = photoW / maxSide; } else { scaleFactor = photoH / maxSide; } bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; return BitmapFactory.decodeFile(photoPath, bmOptions); } }