Here you can find the source of saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)
public static boolean saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)
//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 boolean saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality) { OutputStream stream = null; try {/* w w w .j ava 2 s . c o m*/ File file = new File(path); File filePath = file.getParentFile(); if (!filePath.exists()) { filePath.mkdirs(); } if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } } stream = new FileOutputStream(path); boolean rlt = bmp.compress(format, quality, stream); stream.close(); return rlt; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (Exception e) { // TODO: handle exception return false; } } }