获取的图像的URI存储在可拉伸图像、URI

由网友(拿得起ゝ放得下)分享简介:我加入了几个样本项目在我的应用程序,它看起来不那么空当用户第一次看看吧。与样品项目列表应具有的图像和图像我将使用已存储在应用程序的/ RES /抽拉文件夹。 I am adding a couple of sample items in my application so it doesn't look so emp...

我加入了几个样本项目在我的应用程序,它看起来不那么空当用户第一次看看吧。与样品项目列表应具有的图像和图像我将使用已存储在应用程序的/ RES /抽拉文件夹。

I am adding a couple of sample items in my application so it doesn't look so empty when the user look at it the first time. The list with the sample items should have an image and the image I am going to use is already stored in the /res/drawable-folder of the application.

既然我已经有了加载从URI的物品图像的方法,我想获得的URI的/res/drawable/myImage.jpg,但我似乎并没有能够得到它的权利。

Since I already have a method that load the items images from a URI i'd like to get the URI to the /res/drawable/myImage.jpg but I don't seem to be able to get it right.

的流程如下: 与重新presents图像的URI字符串创建项目。 发送的产品清单到列表 这份名单通过转换字符串URL,然后运行url.openStream()加载在后台任务图像;

The flow is as follows: Create item with string that represents the URI of the image. Send list of items to an List The list loads the image in a background task by converting the string to URL and then run url.openStream();

我已经尝试了几个选项的URI没有任何成功。 android.resource:// ......说不明protocoll 文件://找不到文件

I have tried a few options for the URI without any success. "android.resource://....." says unknow protocoll "file://" file not found

所以,现在我有点失去了关于如何解决这一问题。

So right now I'm a little bit lost about how to fix this..

推荐答案

您应该使用 ContentResolver的打开资源的URI:

You should use ContentResolver to open resource URIs:

Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");
InputStream stream = getContentResolver().openInputStream(uri);

您也可以使用此方法打开文件和内容的URI。

Also you can open file and content URIs using this method.

阅读全文

相关推荐

最新文章