Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; public class Main { public static Bitmap getCompressedBitmap(String str) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(str, options); options.inSampleSize = calculateInSampleSize(options, options.outWidth, options.outHeight); options.inJustDecodeBounds = false; options.inPreferredConfig = Config.RGB_565; options.inDither = true; return BitmapFactory.decodeFile(str, options); } public static int calculateInSampleSize(Options options, int i, int i2) { int i3 = options.outHeight; int i4 = options.outWidth; int i5 = 1; if (i3 > i2 || i4 > i) { i3 /= 3; i4 /= 3; while (i3 / i5 > i2 && i4 / i5 > i) { i5 *= 2; } } return i5; } }