user611089
user611089

Reputation:

android drawable from file path

I have a file path String of the form "e:\...\xxx.jpg" How do I create a drawable from it?

Upvotes: 57

Views: 64413

Answers (1)

Hakan Ozbay
Hakan Ozbay

Reputation: 4719

You can create a Drawable or Bitmap from a string path like this:

String pathName = "/path/to/file/xxx.jpg"; 
Drawable d = Drawable.createFromPath(pathName);

For a Bitmap:

String pathName = "/path/to/file/xxx.jpg";
Bitmap b = BitmapFactory.decodeFile(pathName);

Upvotes: 169

Related Questions