save Bitmap To File - Android android.graphics

Android examples for android.graphics:Bitmap Load Save

Description

save Bitmap To File

Demo Code

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.media.MediaPlayer;
import android.os.Environment;
import android.view.View;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main{

    public static String saveBitmapToFile(final Bitmap bitmap,
            final File outFile, Bitmap.CompressFormat format, int quality)
            throws IOException {
        OutputStream out = null;//from w w  w .  j a v  a  2 s  . c  o m
        try {
            out = new FileOutputStream(outFile);
            bitmap.compress(format, quality, out);
            out.flush();
            return outFile.getAbsolutePath();
        } catch (IOException e) {
            return null;
        } finally {
            if (out != null)
                out.close();
        }
    }

}

Related Tutorials