Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nian88/f1551b04aa56fc23ca6b4e4f78935624 to your computer and use it in GitHub Desktop.
Save nian88/f1551b04aa56fc23ca6b4e4f78935624 to your computer and use it in GitHub Desktop.
Simpan Gambar Dari URL Ke Internal Storage
public void simpan(View v){
Picasso.with(getApplicationContext()).load(url).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
try {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/gambar");
if (!myDir.exists()) {
myDir.mkdirs();
}
String name = new Date().toString() + ".jpg";
myDir = new File(myDir, name);
FileOutputStream out = new FileOutputStream(myDir);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment