Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 无法加载.JPG格式的图像_Reactjs_React Native - Fatal编程技术网

Reactjs 无法加载.JPG格式的图像

Reactjs 无法加载.JPG格式的图像,reactjs,react-native,Reactjs,React Native,我试图从格式为.JPG的本地资源加载图像。但每次它都给我以下的错误 您是否支持.JPG格式?有人能帮我吗?谢谢…如果您确定图像路径正确,则可以将文件夹中的图像从大写字母(.JPG)重命名为小写字母(.JPG) 已在Windows上测试此案例,并可以使用上述解决方案复制和修复它 react本机版本:0.23.1 请澄清: var yourPicture = require('./yourPathToYourPicture/picture.jpg); //Working var yourPict

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


您是否支持.JPG格式?有人能帮我吗?谢谢…

如果您确定图像路径正确,则可以将文件夹中的图像从大写字母(.JPG)重命名为小写字母(.JPG)

已在Windows上测试此案例,并可以使用上述解决方案复制和修复它

react本机版本: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}/>
    );
}
render(){
返回(
);
}

您必须使用
Image
from
react native

import {
  Image,
} from 'react-native';
...
图像有一个称为源的道具

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


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

您可以使用.jpg,我想路径是错误的:)扩展名为.jpg的图像显示在同一文件夹中。只有带.jpg的图像没有显示…正如我在web中读取的那样,图像应该用小写字母,由于Android.React中的xml文件可能不支持.JPG格式,因此您可以将图片编辑为.png或.JPG格式,然后再试一次#cheers@SusylGhimire这是第二个选择。。这意味着你不支持.JPG?有一个博客讨论了为什么你没有从.JPG链接得到回调-应该是解决方案我认为这只发生在Linux中,因为Linux是区分大小写的。对我来说也是一样,我使用的是Windows。我用大写字母写了一个jpg图像,但它没有找到源代码——因为我把目录中的文件名改为.jpg,用小写字母写了它就行了。-Windows也是如此,但问题仍然是一样的。。。react native不支持.JPG??似乎不是这样。正如我写的那样,我使用react native版本0.23.1的大写字母进行了测试,但它不起作用-因此react native似乎不支持图像的大写结尾。:)关于这个话题,我不能再多说了。总之->React Native supports.jpg->React Native不支持.jpg希望能帮助你