Java tutorial
//package com.java2s; import android.graphics.Rect; public class Main { public static int getSampleSizeOfNotTooLarge(Rect rect) { final int FIVE_M = 5 * 1024 * 1024; double ratio = ((double) rect.width()) * rect.height() * 2 / FIVE_M; return ratio >= 1 ? (int) ratio : 1; } }