Here you can find the source of bitmap2File(Bitmap bitmap, File file)
public static final void bitmap2File(Bitmap bitmap, File file)
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.media.ExifInterface; import android.media.ThumbnailUtils; import android.util.Base64; import android.view.View; public class Main{ public static final void bitmap2File(Bitmap bitmap, File file) { bitmap2File(bitmap, file, CompressFormat.JPEG, 100); }//from www . j a v a 2 s . c o m public static final void bitmap2File(Bitmap bitmap, File file, CompressFormat format, int quality) { if (bitmap == null) { throw new NullPointerException("source bitmap is null..."); } if (file == null) { throw new NullPointerException("targe file is null..."); } if (file.exists()) { file.delete(); } FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(file); } catch (FileNotFoundException e) { LogUtility.d(e); } if (outputStream == null) { return; } bitmap.compress(format, quality, outputStream); try { outputStream.flush(); } catch (IOException e) { LogUtility.d(e); } finally { StreamUtility.closeStream(outputStream); } } }