android drawable from file path

时间:2011-04-29 15:45:48

标签: android drawable filepath

我有一个文件路径字符串形式为“e:\ ... \ xxx.jpg” 如何从中创建一个drawable?

1 个答案:

答案 0 :(得分:125)

您可以从字符串路径创建Drawable或Bitmap,如下所示:

 String pathName = "/path/to/file/xxx.jpg"; 
 Drawable d = Drawable.createFromPath(pathName);

对于位图:

String pathName = "/path/to/file/xxx.jpg";
bitmap b = BitmapFactory.decodeFile(pathName);