@Nullable @WorkerThread static File writeBitmapToFile(@NonNull Bitmap bitmap,@NonNull File file){
  FileOutputStream fileStream=null;
  try {
    ByteArrayOutputStream byteStream=new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG,0,byteStream);
    fileStream=new FileOutputStream(file);
    fileStream.write(byteStream.toByteArray());
    return file;
  }
 catch (  IOException e) {
    Log.e(TAG,e.getMessage(),e);
  }
 finally {
    if (fileStream != null) {
      try {
        fileStream.close();
      }
 catch (      IOException e) {
        Log.e(TAG,e.getMessage(),e);
      }
    }
  }
  return null;
}

@ Nullable @ WorkerThread static File writeBitmapToFile ( @ NonNull Bitmap bitmap , @ NonNull File file ) { FileOutputStream fileStream = null ; try { ByteArrayOutputStream byteStream = new ByteArrayOutputStream ( ) ; bitmap . compress ( Bitmap . CompressFormat . PNG , 0 , byteStream ) ; fileStream = new FileOutputStream ( file ) ; fileStream . write ( byteStream . toByteArray ( ) ) ; return file ; } catch ( IOException e ) { Log . e ( TAG , e . getMessage ( ) , e ) ; } finally { if ( fileStream != null ) { try { fileStream . close ( ) ; } catch ( IOException e ) { Log . e ( TAG , e . getMessage ( ) , e ) ; } } } return null ; }
writes the bitmap to disk and returns the new file .
