save Processed Bitmap Image - Android Graphics

Android examples for Graphics:Bitmap Save

Description

save Processed Bitmap Image

Demo Code


//package com.java2s;
import android.graphics.Bitmap;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Main {
    /**/*  ww  w . j a v  a 2  s.  com*/
     * @param bmp                - bitmap to be saved to sdcard
     * @param processedImagePath - path and name where you want it to go
     * @return
     */
    public static boolean saveProcessedImage(Bitmap bmp,
            String processedImagePath) {
        OutputStream outStream = null;
        final int QUALITY_FACTOR = 100;

        File file = new File(processedImagePath);

        try {
            outStream = new FileOutputStream(file);
            try {
                bmp.compress(Bitmap.CompressFormat.PNG, QUALITY_FACTOR,
                        outStream);
                outStream.flush();
            } finally {
                outStream.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }
}

Related Tutorials