Android 将本地图片转为Drawable对象
/**
* 将本地图片转换为 Drawable
* @param context 上下文
* @param file 文件路径
* @return
*/
public static Drawable path2Drawable(Context context, String file) {
if (file == null || file.isEmpty()) {
return null;
}
Drawable drawable = null;
try {
FileInputStream fis = new FileInputStream(file);
Bitmap bitmap = BitmapFactory.decodeStream(fis);
drawable = new BitmapDrawable(context.getResources(), bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return drawable;
}