Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.BitmapFactory; public class Main { public static int MIN_WIDTH = 100; private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { int height = options.outHeight; int width = options.outWidth; int inSampleSize = 1; if (width < MIN_WIDTH) { return inSampleSize; } else { int heightRatio; if (width > height && reqWidth < reqHeight || width < height && reqWidth > reqHeight) { heightRatio = reqWidth; reqWidth = reqHeight; reqHeight = heightRatio; } if (height > reqHeight || width > reqWidth) { heightRatio = Math.round((float) height / (float) reqHeight); int widthRatio = Math.round((float) width / (float) reqWidth); inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio; } return inSampleSize; } } }