Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; public class Main { /** * @param file * @param image_width * @param image_height * @return * @hide */ @SuppressWarnings("unused") private static Bitmap decodeFile(File file, int image_width, int image_height) { try { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(file), null, o); int REQUIRED_HEIGHT = image_height; int REQUIRED_WIDTH = image_width; int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 1; while (true) { if (width_tmp / 2 < REQUIRED_WIDTH && height_tmp / 2 < REQUIRED_HEIGHT) break; width_tmp /= 2; height_tmp /= 2; scale++; } BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; return BitmapFactory.decodeStream(new FileInputStream(file), null, o2); } catch (FileNotFoundException e) { } return null; } }