Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.DisplayMetrics; public class Main { public static Bitmap getSampleBitmap(Activity activity, String filepath) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filepath, options); options.inJustDecodeBounds = false; int width = options.outWidth; int height = options.outHeight; DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int scale = Math.min(width / dm.widthPixels, height / dm.heightPixels); options.inSampleSize = scale; Bitmap bitmap2 = BitmapFactory.decodeFile(filepath, options); return bitmap2; } }