获取的图像的URI存储在可拉伸 [英] Get the URI of an image stored in drawable

查看:175
本文介绍了获取的图像的URI存储在可拉伸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入了几个样本项目在我的应用程序,它看起来不那么空当用户第一次看看吧。与样品项目列表应具有的图像和图像我将使用已存储在应用程序的/ 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.

这篇关于获取的图像的URI存储在可拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆