android drawable from file path

后端 未结 1 2024
广开言路
广开言路 2020-12-07 18:00

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

相关标签:
1条回答
  • 2020-12-07 18:23

    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);
    
    0 讨论(0)
提交回复
热议问题