Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public final static int IMAGE_MAX_SIZE = 2048; public static int scalePow2(int height, int width) { int scale = 1; int size = Math.max(height, width); if (size > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) size) / Math.log(0.5))); } return scale; } }