Android Bitmap Save saveBitmapToFile(Bitmap bitmap, String path)

Here you can find the source of saveBitmapToFile(Bitmap bitmap, String path)

Description

save Bitmap To File

Declaration

public static void saveBitmapToFile(Bitmap bitmap, String path) 

Method Source Code

//package com.java2s;

import java.io.File;

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

import java.io.OutputStream;

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

public class Main {
    public static void saveBitmapToFile(Bitmap bitmap, String path) {
        CompressFormat format = Bitmap.CompressFormat.PNG;
        int quality = 100;
        OutputStream stream = null;
        try {/*ww  w.ja v  a2 s.c  o  m*/

            File file = new File(path);
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }

            stream = new FileOutputStream(path);
            bitmap.compress(format, quality, stream);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. saveToLocal(Bitmap bmp, String fileName)
  2. storeImage(Context context, Bitmap image)
  3. saveBitmap(Bitmap bitmap, String filename)
  4. saveBitmap2SD(Bitmap bitmap, Context context, String filePath, String fileName)
  5. addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData)
  6. save(Bitmap bitmap, String fileName)
  7. saveBitmapToFile(Bitmap bitmap, String filename)
  8. saveBitmap(Bitmap bmp, String path, CompressFormat format)
  9. saveBitmap(Bitmap image)