Skip to content

Instantly share code, notes, and snippets.

@dron247
Created August 2, 2017 07:17
Show Gist options
  • Save dron247/9f2dfe44a3bec7cfaff0c26ca4d5b3aa to your computer and use it in GitHub Desktop.
Save dron247/9f2dfe44a3bec7cfaff0c26ca4d5b3aa to your computer and use it in GitHub Desktop.
private File saveBitmap(Bitmap bmp, String fileName) {
if (bmp == null) return null;
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("file exist " + file + ",Bitmap= " + bmp);
}
try {
outStream = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
log("error save " + e.getMessage());
}
log("file = " + file);
return file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment