Two example works for me, for your reference.
Bitmap bitmap = Utils.decodeBase64(base64);
try {
File file = new File(filePath);
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
}
catch (Exception e) {
e.printStackTrace();
LOG.i(null, "Save file error!");
return false;
}
and this one
Bitmap savePic = Utils.decodeBase64(base64);
File file = new File(filePath);
File path = new File(file.getParent());
if (savePic != null) {
try {
// build directory
if (file.getParent() != null && !path.isDirectory()) {
path.mkdirs();
}
// output image to file
FileOutputStream fos = new FileOutputStream(filePath);
savePic.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
ret = true;
} catch (Exception e) {
e.printStackTrace();
}
} else {
LOG.i(TAG, "savePicture image parsing error");
}