gpt4 book ai didi

java - android,如何从内存中的位图/可绘制对象获取资源标识符?

转载 作者:行者123 更新时间:2023-12-02 08:05:19 25 4
gpt4 key购买 nike

我正在使用一个数组列表,该数组列表是通过下载从 RSS 提要引用的文件来填充的。我认为此时它还没有保存到磁盘上。

  1. 如果我不保存到磁盘,实际上我还会有资源标识符吗?
  2. 如果是这样,我该如何检索它?

强制性示例代码:

URL url = new URL("http://someurl.com/rss");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
NodeList postList = doc.getElementsByTagName("item");
thumbIds = new Integer[postList.getLength()];
for (int i = 0; i < postList.getLength(); i++) {
// extract post
Node post = postList.item(i);
Element postElement = (Element) post;
NodeList titleList = postElement.getElementsByTagName("media:thumbnail");
Element titleElement = (Element) titleList.item(0);
String myUrl = titleElement.getAttribute("url").toString();
if(myUrl != null) {

thumbs.add(new BitmapDrawable(fetchBitmap(myUrl)));
}
}
public static Bitmap fetchBitmap(String url) {

URL newurl = null;
try {
newurl = new URL(url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Bitmap returnBitmap = null;
try {
returnBitmap = BitmapFactory.decodeStream(newurl.openConnection()
.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnBitmap;
}

提前致谢!

最佳答案

恐怕答案是否定的。

您只能获取/res 文件夹中声明的文件的资源标识符。如果您将位图下载到您的应用程序并想要存储它们,我目前能想到的唯一解决方案是将它们保存为文件(缓存或外部)或数据库中。

关于java - android,如何从内存中的位图/可绘制对象获取资源标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8277415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com