Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.BitmapFactory; public class Main { public static int getFitInSampleSize(int reqWidth, int reqHeight, BitmapFactory.Options options) { int inSampleSize = 1; if (options.outWidth > reqWidth || options.outHeight > reqHeight) { int widthRatio = Math.round((float) options.outWidth / (float) reqWidth); int heightRatio = Math.round((float) options.outHeight / (float) reqHeight); inSampleSize = Math.min(widthRatio, heightRatio); } return inSampleSize; } }