无法加载.JPG格式的图像

时间:2016-06-29 10:31:12

标签: reactjs react-native

我试图从格式为.JPG的本地资源加载图片。但每次它都会给我以下错误。

enter image description here

做出反应原生支持.JPG格式?谁可以帮我这个事 ?感谢...

2 个答案:

答案 0 :(得分:1)

如果您确定image_path是正确的,那么您可以将文件夹中的图像从大写字母(.JPG)重命名为小写字母(.jpg)。

测试了Windows的这种情况,可以使用上述解决方案重现并修复它。

react-native version:0.23.1

澄清:

var yourPicture = require('./yourPathToYourPicture/picture.jpg); //Working

var yourPicture = require('./yourPathToYourPicture/picture.JPG); //Not-Working
  

解决大写字母问题的解决方案:使用小写字母将图片保存在项目文件夹中yourPicture.JPG - > yourPicture.jpg

使用您的图片

render(){
    return(
        <Image source={yourPicture}/>
    );
}

答案 1 :(得分:0)

您必须使用Image

中的react-native
import {
  Image,
} from 'react-native';
...

图片有一个名为source的道具

<Image source={require('./img/fotofondo_app.jpg')}/>

如果错误仍然存​​在,请尝试执行react-native run-android因为图像文件没有被热读。