1

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.

Telmo Pimentel Mota
  • 4,033
  • 16
  • 22

1 Answers1

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