I have a file path String of the form "e:\...\xxx.jpg" How do I create a drawable from it?
            Asked
            
        
        
            Active
            
        
            Viewed 6.3k times
        
    1 Answers
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
- 
                    3I used to load bitmaps to ImageViews. But thanks to your answer, I just tried to convert my jpg assets into Drawables and now my app loads faster. – Ignacio Roda Oct 18 '15 at 06:25
- 
                    3Simple, neat and clean! +1 for keeping it TL;DR :) – Aviram Fireberger Jun 02 '19 at 11:11
