我在将图像转换为Drawable
对象时遇到问题。我使用的图像转换:如何将图像从URL转换为可绘制
public Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream)new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
System.out.println("Exc=" + e);
return null;
}
}
我试图把Drawable
在HashMap
,并插入到一个ListAdapter
,但是Drawable
的价值始终是一样的东西[email protected]
而不是整数,我在logcat中得到的消息
resolveUri失败的坏位URI”。
我这是怎么把Drawable
在HashMap
:
map.put("cover", String.valueOf(
Main.this.LoadImageFromWebOperations("http://www.asdfasfs.com/dasfas.jpg")));
尝试改为这个map.put(“cover”,Main.this.LoadImageFromWebOperations(“http://www.asdfasfs.com/dasfas.jpg”)); – ingsaurabh 2011-02-24 10:48:33
这是行不通的,eclipse说:“方法put(String,String)在类型HashMap中不适用于参数(String,Drawable)” –
robs
2011-02-24 10:57:54
显然你必须改变你的通用定义'HashMap'。它应该是'HashMap'。 –
2011-02-24 11:20:33