Last active
March 29, 2016 04:58
-
-
Save aldoKelvianto/fd9caaa7d3d4962edbb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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