Android Bitmap Save saveBitmapToFile(Bitmap bitmap, String filename)

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

Description

save Bitmap To File

Declaration

public static boolean saveBitmapToFile(Bitmap bitmap, String filename) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import java.io.ByteArrayOutputStream;
import java.io.File;

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

public class Main {
    public static boolean saveBitmapToFile(Bitmap bitmap, String filename) {
        boolean result = false;
        FileOutputStream fos = null;
        try {/*from  ww w.  jav  a 2  s.c  o  m*/
            fos = new FileOutputStream(new File(filename));
            fos.write(bitmap2byte(bitmap));
            result = true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != fos) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return result;

    }

    public static byte[] bitmap2byte(Bitmap bitmap) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        return baos.toByteArray();
    }
}

Related

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