11

I have some 10 images saved in drawable folder. I want to move them to internal file storage.

Is this possible?

I have searched a lot but, I only found links where we can save image to internal file system from given path, but I want to save images from drawable folder to internal file storage in Android and I want to achieve this through code.

Any help will greatly be appreciated.

Thank you.

JorgeAmVF
  • 1,660
  • 3
  • 21
  • 32
Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61
  • 3
    Shrikant buddy u can follow this [drawable-sdcard][1] and [drawable-sdcard2][2]. Thanks furqi [1]: http://stackoverflow.com/questions/10558053/save-image-to-sdcard-from-drawble-resource-on-android [2]: http://stackoverflow.com/questions/10198620/save-image-from-drawable-to-sdcard-in-camera-activity – Furqi Sep 24 '12 at 06:40

1 Answers1

24

Saving image to sdcard from drawble resource:

Say you have an image namely ic_launcher in your drawable. Then get a bitmap object from this image like:

Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);

The path to SD Card can be retrieved using:

String extStorageDirectory = Environment.getExternalStorageDirectory().toString();

Then save to sdcard on button click using:

File file = new File(extStorageDirectory, "ic_launcher.PNG");
    outStream = new FileOutputStream(file);
    bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
    outStream.flush();
    outStream.close();

Don't forget to add android.permission.WRITE_EXTERNAL_STORAGE permission.

Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61
  • 4
    Does it save in internal sdcard? I dont think so? Its for external sdcard. – MGDroid Sep 15 '13 at 00:03
  • 1
    Why dimension of png changed after saving? My orignal png in drawable is 180x40, but the image saved to internal storage is 540x120. Exactly 3 time height and width. Any clue? – Rishabh Chandel Jun 17 '17 at 23:06