Last active
April 6, 2016 13:36
-
-
Save nian88/f1551b04aa56fc23ca6b4e4f78935624 to your computer and use it in GitHub Desktop.
Simpan Gambar Dari URL Ke Internal Storage
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
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