Java tutorial
//package com.java2s; import android.graphics.BitmapFactory; public class Main { public static int getSampleSizeAdjustToScreen(String filePath, int[] screenSize) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); int w = (int) Math.ceil(options.outWidth / (float) screenSize[0]); int h = (int) Math.ceil(options.outHeight / (float) screenSize[1]); if (h > 1 || w > 1) { if (h > w) { options.inSampleSize = h; } else { options.inSampleSize = w; } } return options.inSampleSize; } }