Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Bitmap; import static android.graphics.Bitmap.*; public class Main { public static Bitmap scaleBitmap(Bitmap source, int targetSize) { int sourceW = source.getWidth(); int sourceH = source.getHeight(); float scaleFactor = (float) Math.sqrt(source.getByteCount() / targetSize); int dstWidth = (int) (sourceW / scaleFactor); int dstHeight = (int) (sourceH / scaleFactor); Bitmap scaledBitmap = createScaledBitmap(source, dstWidth, dstHeight, true); return scaledBitmap; } }