<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
//Bitmap.CompressFormat.PNG
public void drawableToFile(Drawable drawable, String filePath, Bitmap.CompressFormat format) {
if (drawable == null)
return;
try {
File file = new File(filePath);
if (file.exists())
file.delete();
if (!file.exists())
file.createNewFile();
FileOutputStream out = null;
out = new FileOutputStream(file);
((BitmapDrawable) drawable).getBitmap().compress(format, 100, out);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}