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