Android Bitmap Save storeBitmapToFile(Bitmap bitmap, String filePath)

Here you can find the source of storeBitmapToFile(Bitmap bitmap, String filePath)

Description

store Bitmap To File

Declaration

public static boolean storeBitmapToFile(Bitmap bitmap, String filePath) 

Method Source Code

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

import java.io.FileOutputStream;

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

import android.os.Environment;

public class Main {
    public static boolean storeBitmapToFile(Bitmap bitmap, String filePath) {
        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            try {
                BufferedOutputStream bos = new BufferedOutputStream(
                        new FileOutputStream(filePath));
                bitmap.compress(CompressFormat.PNG, 50, bos);
                bos.flush();/*from  w  ww.  j a v a 2  s  .  co m*/
                bos.close();
            } catch (Exception e) {
                return false;
            }
            return true;
        }

        return false;
    }
}

Related

  1. saveBitmapPNGWithBackgroundColor( String strFileName, Bitmap bitmap, int nBackgroundColor)
  2. saveBitmapToPath(Context ctxt, String path, String filename, Bitmap bm)
  3. saveJPEGBitmap(Bitmap bmp, String path)
  4. saveJpegFile(String fileName, Bitmap bitmap)
  5. savePNGBitmap(Bitmap bmp, String path)
  6. writeToFile(Bitmap bitmap, String filePath, int quality)