Skip to content

Instantly share code, notes, and snippets.

@aldoKelvianto
Last active March 29, 2016 04:58
Show Gist options
  • Save aldoKelvianto/fd9caaa7d3d4962edbb9 to your computer and use it in GitHub Desktop.
Save aldoKelvianto/fd9caaa7d3d4962edbb9 to your computer and use it in GitHub Desktop.
private String saveImageToInternalDrive() {
Bitmap bitmap;
OutputStream outputStream;
bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();
File filePath = getFilesDir();
File imageDir = new File(filePath.getAbsolutePath() + "YourDirName");
if(!imageDir.exists()){
imageDir.mkdir();
}
File imageFile = new File(imageDir, "YourImage.png");
boolean isSaveSuccessful;
try {
outputStream = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
outputStream.flush();
outputStream.close();
isSaveSuccessful = true;
} catch (IOException e) {
isSaveSuccessful = false;
}
if(isSaveSuccessful){
return imageFile.getAbsolutePath();
}else{
return "Failed to save image";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment