54

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

skaffman
  • 398,947
  • 96
  • 818
  • 769

1 Answers1

165

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);
Hakan Ozbay
  • 4,639
  • 2
  • 22
  • 28