Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; public class Main { public static final Bitmap getBitmap(String fileName) { Bitmap bitmap = null; try { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(fileName, options); options.inSampleSize = Math.max(1, (int) Math .ceil(Math.max((double) options.outWidth / 1024f, (double) options.outHeight / 1024f))); options.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeFile(fileName, options); } catch (OutOfMemoryError error) { error.printStackTrace(); } return bitmap; } }