获取内容URI从Android文件路径 [英] Get content uri from file path in android
问题描述
我知道图像的绝对路径(说的如/sdcard/cats.jpg)。有没有什么办法的内容URI这个文件?
I know the absolute path of an image (say for eg, /sdcard/cats.jpg). Is there any way to the content uri for this file ?
其实在我的code我下载一个图像,并保存在一个特定的位置。为了目前我打开使用路径的文件设置在ImageView的形象,得到了字节和创建位图,然后设置在ImageView的位图。这是一个非常缓慢的过程,而不是如果我能得到的内容URI话,我可以很容易使用的方法 ImageView.setImageUri(URI)
Actually in my code I download an image and save it at a particular location. In order to set the image in an ImageView currently I open the file using the path, get the bytes and create a bitmap and then set the bitmap in the ImageView. This is a very slow process, instead if I could get the content uri then I could very easily use the method ImageView.setImageUri(uri)
推荐答案
尝试使用:
ImageView.setImageURI(Uri.fromFile(new File("/sdcard/cats.jpg")));
或者用:
ImageView.setImageURI(Uri.parse(new File("/sdcard/cats.jpg").toString()));
这篇关于获取内容URI从Android文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!