Android使用路径中的空格和通用图像加载器加载本地图像

Android loading local image with space in path and with universal image loader(Android使用路径中的空格和通用图像加载器加载本地图像)

本文介绍了Android使用路径中的空格和通用图像加载器加载本地图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 android 应用程序,我想在通用图像加载器的帮助下显示本地图像.但是当我尝试显示在其本地图像路径中有空间的图像时,它无法显示图像.我尝试了以下方式:

I am developing android application in which I want to display local image with the help of universal image loader. But when I try to display image which has space in it's local image path then it not able to display image. I tried it in following manner:

Uri.fromFile(new File(newImagePath)).toString();

我收到以下错误:

java.io.FileNotFoundException: /storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20150421-WA0002.jpg: open failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.open(IoBridge.java:456)

如果尝试加载其本地路径中没有空格的图像,则它可以正常工作,但路径中有空格的图像会导致问题.需要一些帮助.谢谢.

If tried to load image which has no space in its local path then it works fine but image with space in its path cause issue. Need some help. Thank you.

推荐答案

其实是通用图片加载器的问题.https://github.com/nostra13/Android-Universal-Image-Loader/issues/371

Actually its problem with universal image loader. https://github.com/nostra13/Android-Universal-Image-Loader/issues/371

因此,您只需解码图像路径即可删除空间.

So you just have decode your image path to remove space.

根据上面链接中的讨论,我得到了解决方案:

As per discussion in above link I got the solution :

final String uri = Uri.fromFile(file).toString();
final String decoded = Uri.decode(uri);

ImageLoader.getInstance().displayImage(decoded, imageView);

这篇关于Android使用路径中的空格和通用图像加载器加载本地图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android使用路径中的空格和通用图像加载器加载本地图像

基础教程推荐