BlackberryChennai
BlackberryChennai

Reputation: 436

How to read an image from drawable to File object in java?

I have an image in the res folder. I want it to be available in the File(java.io.File) object.

I am using:

File f = new File(new URI("drawable/small");

where small is the name of the image.

Upvotes: 4

Views: 2506

Answers (2)

Saqib Razaq
Saqib Razaq

Reputation: 874

        InputStream ins = getResources().openRawResource(R.drawable.icon);
        BufferedReader br = new BufferedReader(new InputStreamReader(ins));
        StringBuffer sb;
        String line;
        while((line = br.readLine()) != null){
            sb.append(line);
            }

        File f = new File(sb.toString());

You can use openRawResource to copy a binary across from your raw resource folder to the device or in this case the File

Upvotes: 3

Pete Houston
Pete Houston

Reputation: 15089

Is it something like?

File f = new File(Uri.parse("android.resource://com.package.AppName/res/drawable/resource_name"));

Upvotes: -1

Related Questions