android drawable from file path

user611089 picture user611089 · Apr 29, 2011 · Viewed 56.6k times · Source

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

Answer

Hakan Ozbay picture Hakan Ozbay · Apr 29, 2011

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);