save Bitmap to a File - Android Graphics

Android examples for Graphics:Bitmap File

Description

save Bitmap to a File

Demo Code


//package com.java2s;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;

public class Main {
    public static void saveBitmap(String picPath, Bitmap bitmap) {
        File f = new File(picPath);
        if (f.exists()) {
            f.delete();//from  w  w  w  .  j a  va  2  s  .  com
        }

        FileOutputStream out = null;
        try {
            out = new FileOutputStream(f);
            bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
            out.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related Tutorials