Java tutorial
//package com.java2s; import android.graphics.BitmapFactory; public class Main { /** * caculate the bitmap sampleSize * * @return inSampleSize */ private static int caculateInSampleSize(BitmapFactory.Options options, int rqsW, int rqsH) { final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (rqsW == 0 || rqsH == 0) return 1; if (height > rqsH || width > rqsW) { final int heightRatio = Math.round((float) height / (float) rqsH); final int widthRatio = Math.round((float) width / (float) rqsW); inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } return inSampleSize; } }