如何用 React Native 和 Expo 展示图片?

How to display image with React Native and Expo?

我正在制作我的第一个 React Native 项目,我已经使用 create-react-native-app 命令来设置所有内容。但是,当我尝试让图像显示在 Expo 中时,它会给我一条错误消息,提示它找不到 png 文件。我目前在 './img/record_video.png' 下有该文件(它只是一个我将用作按钮的图标)。 Here's my project layout and the code I'm using to call it

也就是说,我正在使用 <Image source={require('./img/record_video.png')} /> 来调用该文件。

This is the error message I receive on my phone from the Expo app 简而言之就是 undefined Unable to resolve module './img/record_video.png' from C:\Users\ddude\Desktop\AwesomeProject\App.js':The module './img/record_video.png' could not be found from 'C:\Users\ddude\Desktop\AwesomeProject\App.js'. Indeed, none of these files exist: *'record_video.png' *'C:\Users\ddude\Desktop\AwesomeProject\img\record_video.png\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)'

我不确定是不是因为我正在使用 Expo 并且它没有正确导出到 phone,或者它是否需要在一个特别命名的文件夹中。任何帮助将不胜感激,谢谢!

删除下划线并将图像资源重命名为 record-video.png、record-voice.png 和 convert-to-text.png。重新启动包管理器并尝试。

Just another observation I do not see an image record_audio.png in img folder as required in second line.

希望对您有所帮助。