Java tutorial
//package com.java2s; import android.graphics.BitmapFactory; public class Main { public static float calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; float inSampleSize = 1; if (height >= reqHeight || width >= reqWidth) { if (width > height) { inSampleSize = height / (float) reqHeight; } else { inSampleSize = width / (float) reqWidth; } } else { inSampleSize = Math.min((float) width / reqWidth, (float) height / reqHeight); } return inSampleSize; } }