android drawable from file path

AndroidDrawableFilepath

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser611089View Question on Stackoverflow
Solution 1 - AndroidHakan OzbayView Answer on Stackoverflow