public static void writeToFile ( Bitmap bitmap , String dir , String filename ) throws FileNotFoundException , IOException { File sdCard = Environment . getExternalStorageDirectory ( ) ; File dirFile = new File ( sdCard . getAbsolutePath ( ) + "/" + dir ) ; dirFile . mkdirs ( ) ; File f = new File ( dirFile , filename ) ; FileOutputStream fos = new FileOutputStream ( f , false ) ; bitmap . compress ( CompressFormat . PNG , 100 /*ignored for PNG*/ , fos ) ; fos . flush ( ) ; fos . close ( ) ; }
Write the given bitmap to a file in the external storage . Requires android . permission . WRITE_EXTERNAL_STORAGE permission .