Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Bitmap; import android.os.Environment; import android.util.Log; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; public class Main { public static File bitmap2File(Bitmap bitmap, String filename) { String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); OutputStream outStream = null; File file = new File(extStorageDirectory, filename + ".png"); if (file.exists()) { file.delete(); file = new File(extStorageDirectory, filename + ".png"); Log.e("file exist", "" + file + ",Bitmap= " + filename); } try { outStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream); outStream.flush(); outStream.close(); } catch (Exception e) { e.printStackTrace(); } Log.e("file", "" + file); return file; } }