user1835954
user1835954

Reputation: 51

How to Store Image from Drawable folder to SDCard in Android?

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.

Upvotes: 1

Views: 1775

Answers (1)

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21181

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.

Upvotes: 1

Related Questions