Skip to content Skip to sidebar Skip to footer

How To Copy The Sample Images From The Drawable Folder To The Sdcard Folder, Programmaticaly?

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 =

Solution 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.

Best Regards, Zhenghong Wang

Post a Comment for "How To Copy The Sample Images From The Drawable Folder To The Sdcard Folder, Programmaticaly?"