Java tutorial
//package com.java2s; import android.graphics.*; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class Main { public static String simpleCompressImage(String path, String newPath) { Bitmap bitmap = BitmapFactory.decodeFile(path); FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(newPath); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } recycle(bitmap); return newPath; } /** * Garbage recycle * * @throws */ public static void recycle(Bitmap bitmap) { if (bitmap != null && !bitmap.isRecycled()) { // recycle bitmap and assign to null bitmap.recycle(); bitmap = null; } System.gc(); } }