我在将图像转换为Drawable
对象时遇到问题。我正在使用以下图像转换图像:
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
的值始终类似于android.graphics.drawable.BitmapDrawable@405359b0
而不是整数,我得到了消息在logcat中
resolveUri在错误的位图uri上失败”。
这是将Drawable
放入HashMap
的方式:
map.put("cover", String.valueOf(
Main.this.LoadImageFromWebOperations("http://www.asdfasfs.com/dasfas.jpg")));
您为什么期望drawable为整数?您可以将其分配给imageView
。
您的项目中有些项目可以使用其ID进行引用,这是正确的,但是还有其他事情。
R.drawable.icon
不是Drawable
,在同样的意义上,R.view.your_Button
不是Button
。您会在此调用类似getViewFromId()
的名称。如果您具有这样的功能:
doSomethingWithView(R.view.id);
然后,它就不能与(课程的伪代码)一起使用
myView = new Button();
doSomethingWithView(myView);
因此,如果您的函数与R.drawable.id
一起使用,则它与Drawable一起使用的可能性很小(除非课程重载)。>