0

I have pictures/images in my drawable folder and I want to copy all of it in my sdcard folder with that same quality and details? If I have for example this.

Integer[] mThumbIds = {
        R.drawable.pic_1, R.drawable.pic_2,
        R.drawable.pic_3, R.drawable.pic_4,
        R.drawable.pic_5, R.drawable.pic_6,
        R.drawable.pic_7
};

And then my app creates an own directory in sdcard, like this:

String newFolder = "/myFolder2";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + newFolder);
myNewFolder.mkdir();

How can I achieve to transfer all those pictures in drawable to the created folder in sdcard with the same quality and details?

aaaaAndroid
  • 19
  • 1
  • 8
  • Please take a look at this post http://stackoverflow.com/questions/8664440/how-to-copy-image-file-from-gallary-to-other-folder-programatically-in-android It explains how to copy the pictures from one folder to another – Marcin S. Sep 20 '12 at 02:25
  • have You considered usage of asserts instead of resources? Seems it would be way easier to copy then (obtain stream, file descriptor etc). – sandrstar Sep 20 '12 at 02:29
  • @MarcinS. the example is not so clear for me, can you show it as an answer? – aaaaAndroid Sep 20 '12 at 02:31
  • @sandrstar, hmm. what are you trying to tell me? can't understand it. – aaaaAndroid Sep 20 '12 at 02:32
  • sorry, a meant assets and http://developer.android.com/reference/android/content/res/AssetManager.html – sandrstar Sep 20 '12 at 02:52

1 Answers1

3

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.

Best Regards, Zhenghong Wang

Zhenghong Wang
  • 2,117
  • 17
  • 19
  • This is an accurate answer; however, using the drawable folder for anything but drawables is strongly discouraged. As mentioned above, the assets folder is designed specifically for the OP intends to do. – 323go Sep 20 '12 at 03:07
  • ok thank you for the infos, ok the assets folder. how can i transfer images from there to sdcard? – aaaaAndroid Sep 20 '12 at 04:19
  • There is a sample here. http://stackoverflow.com/questions/4447477/android-how-to-copy-files-in-assets-to-sdcard – Zhenghong Wang Sep 24 '12 at 02:43