【发布时间】:2017-08-26 12:33:22
【问题描述】:
首先我搜索了很多,但没有找到适合我的情况的解决方案,我需要将 imageUrl 转换为可绘制的,我尝试过的:
File imageFile = DiskCacheUtils.findInCache(c.profilePhoto, com.nostra13.universalimageloader.core.ImageLoader.getInstance().getDiscCache());
String file_target = "file://" + imageFile.getPath();
BitmapDrawable bitDraw = (BitmapDrawable) BitmapDrawable.createFromPath(file_target);
if (profilePhotos.size() == 4) break;
BitmapDrawable drawable = bitDraw; //getResources().getDrawable(c.profilePhoto);
drawable.setBounds(0, 0, width, height);
profilePhotos.add(drawable);
我也尝试通过 Glide 将图像加载到位图中,但没有成功。
我怎样才能做到这一点?
提前致谢。
【问题讨论】:
-
file_target不是路径。imageFile.getPath()是一条路径。createFromPath(),根据其名称,似乎需要一个路径,而您没有提供路径。除此之外,请随意用实际的计算机编程术语解释您的代码 sn-p 存在哪些问题,以及对于 Glide 而言“但没有工作”是什么意思。 -
你试过
Drawable#createFromStream()吗? -
@sam 你的两个网址都没有提供图片路径。
-
@CommonsWare 很好,我尝试通过 ImageLoader 获取缓存的图像,以获取使我将其用作可绘制的路径图像。但它总是因 NPE 异常或许多其他异常而失败,我如何才能得到最终结果? (来自 url 的可绘制图像)。
标签: android android-drawable android-image android-glide