Created
September 8, 2018 20:05
-
-
Save Binary-Finery/037e1664d7af494df8baa1a244ed049f to your computer and use it in GitHub Desktop.
Save bitmap to external storage and use media scanner to display image in gallery
This file contains hidden or 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 void savePalette(Bitmap bitmap) { | |
String root = Environment.getExternalStorageDirectory().toString(); | |
File myDir = new File(root + "/palette.io"); | |
if(!myDir.exists()){ | |
myDir.mkdirs(); | |
} | |
String fileName = "palette-io-generated-" + System.currentTimeMillis() + ".jpg"; | |
File file = new File(myDir, fileName); | |
try { | |
FileOutputStream out = new FileOutputStream(file); | |
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); | |
out.flush(); | |
out.close(); | |
MediaScannerConnection.scanFile(this, | |
new String[]{file.toString()}, null, | |
new MediaScannerConnection.OnScanCompletedListener() { | |
public void onScanCompleted(String path, Uri uri) { | |
Log.i("ExternalStorage", "Scanned " + path + ":"); | |
Log.i("ExternalStorage", "-> uri=" + uri); | |
} | |
}); | |
Msg.build(this, "palette saved").show(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Msg.build(this, e.getMessage()).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment