save Bitmap to a File Path - Android Graphics

Android examples for Graphics:Bitmap Save

Description

save Bitmap to a File Path

Demo Code


//package com.java2s;
import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

public class Main {
    public static boolean saveBitmap(Bitmap bitmap, String saveName)
            throws IOException {
        if (bitmap == null)
            return false;
        File file = new File(saveName);
        if (file.exists()) {
            file.delete();//from w  w  w. j  a  va  2  s. c o m
        }
        BufferedOutputStream os = new BufferedOutputStream(
                new FileOutputStream(file));
        bitmap.compress(CompressFormat.JPEG, 80, os);
        os.flush();
        os.close();
        return true;
    }
}

Related Tutorials