Java tutorial
//package com.java2s; import java.io.File; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { public static Bitmap decodeBitmap(File file, int reqHeight, int reqWidth) { // Get image size of file BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(file.getAbsolutePath(), options); final int height = options.outHeight; final int width = options.outWidth; // Calculate sample size if (height > reqHeight || width > reqWidth) { final int heightRatio = Math.round((float) height / (float) reqHeight); final int widthRatio = Math.round((float) width / (float) reqWidth); options.inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } // Decode bitmap options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true; options.inDither = false; return BitmapFactory.decodeFile(file.getAbsolutePath(), options); } }