Android: Saving .png From Url Into App Internal Storage
I'm relatively new to android, and I'm trying to modify an android app such that it downloads a profile picture (preferably in PNG) from a URL, and saves it in the com.companyName.
Solution 1:
try this first get bitmap image from url
BitmapmIcon11=null;
try {
InputStreamin=newjava.net.URL(url).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.d("Error", e.getStackTrace().toString());
}
and to save bitmap image please check the ans ofGoCrazy
Solution 2:
Try this
voidgetImage(String string_url)
{
//Generate Bitmap from URLURLurl_value=newURL(string_url);
Bitmapimage=
BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
//Export File to local DirectoryOutputStreamstream=newFileOutputStream("path/file_name.png");
/* Write bitmap to file using JPEG or PNG and 80% quality hint for JPEG. */
bitmap.compress(CompressFormat.PNG, 80, stream);
stream.close();
}
Post a Comment for "Android: Saving .png From Url Into App Internal Storage"