Android Bitmap Save saveBitmap(Bitmap bmp, String path, CompressFormat format)

Here you can find the source of saveBitmap(Bitmap bmp, String path, CompressFormat format)

Description

save Bitmap

Declaration

private static boolean saveBitmap(Bitmap bmp, String path,
            CompressFormat format) 

Method Source Code

//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;

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

public class Main {
    private static boolean saveBitmap(Bitmap bmp, String path,
            CompressFormat format) {/*from  w  w w .j  a  va  2s . c  o m*/
        if (bmp == null || path == null) {
            return false;
        }
        try {
            File file = new File(path);
            if (!file.exists()) {
                file.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(file);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bmp.compress(format, 100, baos);
            fos.write(baos.toByteArray());
            baos.flush();
            fos.flush();
            baos.close();
            fos.close();

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

Related

  1. saveBitmap2SD(Bitmap bitmap, Context context, String filePath, String fileName)
  2. addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData)
  3. saveBitmapToFile(Bitmap bitmap, String path)
  4. save(Bitmap bitmap, String fileName)
  5. saveBitmapToFile(Bitmap bitmap, String filename)
  6. saveBitmap(Bitmap image)
  7. saveBitmap(File file, Bitmap bitmap)
  8. saveBitmap(File saveToFile, Bitmap bitmapToSave)
  9. saveBitmapAsJpgAtSd(Bitmap mBitmap, String dirPath, String fileName)