Java tutorial
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; public class Main { private final static String TAG = "ZambelzUtility"; /** * * @param file */ public static void decodeFile(File file) { Bitmap bitmap = null; try { // Decode image size BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; FileInputStream fileInputStream = new FileInputStream(file); BitmapFactory.decodeStream(fileInputStream, null, options); fileInputStream.close(); int scale = 1; if (options.outHeight > 500 || options.outWidth > 500) { scale = (int) Math.pow(2, (int) Math.round( Math.log(500 / (double) Math.max(options.outHeight, options.outWidth)) / Math.log(0.5))); } // Decode with inSampleSize BitmapFactory.Options options2 = new BitmapFactory.Options(); options2.inSampleSize = scale; fileInputStream = new FileInputStream(file); bitmap = BitmapFactory.decodeStream(fileInputStream, null, options2); fileInputStream.close(); FileOutputStream output = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, output); output.flush(); output.close(); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } }