I want to Store Image from Drawable folder to SDCard in Android.I tried a lot but I could not find the solution.Please Someone help me for my this issue.Thank you.
Asked
Active
Viewed 1,773 times
1
-
[this one](http://stackoverflow.com/questions/7953436/copy-a-image-from-res-directory) – Mohammed Azharuddin Shaikh Nov 28 '12 at 04:34
-
suppose i have to store image in sdcard from Image URL.How to do that.Suppose my Image URL is "a3.twimg.com/profile_images/670625317/… to store this image in SDCard.Thank You. – user1835954 Nov 28 '12 at 04:43
1 Answers
1
These images in drawable folder can be accessed by BitmapFactory, you can save the bitmap to PNG or JPG.
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
File sd = Environment.getExternalStorageDirectory();
String fileName = "test.png";
File dest = new File(sd, fileName);
try {
FileOutputStream out;
out = new FileOutputStream(dest);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
For other type of images, I think put them into assets folder is a better way.

Ram kiran Pachigolla
- 20,897
- 15
- 57
- 78
-
Thanks a lot..it works fine...suppose i have to store image in sdcard from Image URL.How to do that.Suppose my Image URL is "http://a3.twimg.com/profile_images/670625317/aam-logo-v3-twitter.png".How to store this image in SDCard.Thank You. – user1835954 Nov 28 '12 at 04:42
-
you need to parse the webservice first and then convert the string into bitmap image and then store it to sdcard – Ram kiran Pachigolla Nov 28 '12 at 04:45