图像无法通过网址加载

时间:2016-07-08 10:45:26

标签: android react-native

图片对象不会通过网址加载图片。

<Image style={{height: 120, width: 120}} source={{uri: 'http://somedomain.com/'+this.props.icon}}/>

如果我通过RNFS将此图像下载到本地目录(我已经检查了正确下载的图像)并尝试加载,那么它将失败:

<Image style={{height: 120, width: 120}} source={{uri: 'res/'+this.props.icon}}/>

即使我尝试使用RNFS常量路径,它也不起作用:

<Image style={{height: 120, width: 120}} source={{uri: RNFS.DocumentDirectoryPath+'/res/'+this.props.icon}}/>

UPD 我不知道为什么但是远程图像有时不起作用(在某些域上独立于http或https) 我在渲染之前检查了每个本地图像:

RNFS.exists(LOGOPATH+this.props.logo).then((data)=> {
  console.log(data)
})

每个图像都返回true,表示路径正确

1 个答案:

答案 0 :(得分:1)

您可以在java文件中使用此方法

public void loadPimage(String picUrlString){

    Glide.with(this).load(picUrlString).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(YourImageView);
}

并像这样称呼它

loadPimage(YourURL);

但不要忘记将compile 'com.github.bumptech.glide:glide:3.7.0'添加到Build.gradle文件中的依赖项