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

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,077
  • 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