Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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();
    }
}