如何使用React Native显示本地JPG图像?

时间:2017-05-17 15:08:43

标签: react-native

RN是否支持本地静态JPG图像?所有示例代码here都与PNG图像有关。

我在打包控制台中看到错误<animate>。它必须不是图像位置问题,如果我将图像名称更改为"TypeError: unsupported file type",它就有效。感谢。

test.png

2 个答案:

答案 0 :(得分:0)

你只需要这样做:

<Image source={require('./images/image.jpg')} />

如果您正在呼叫,请在文件夹中说文件夹图像不存在,您需要执行require('../images/image.jpg')并检查图像是否真的是jpg如果您想查看图像的扩展名:

  1. 启动Windows资源管理器,您可以通过打开任何文件夹来执行此操作。
  2. 点击整理。
  3. 点击文件夹和搜索选项。
  4. 单击“视图”选项卡。
  5. 向下滚动,直到您发现隐藏已知文件类型的扩展名为止, 单击复选框取消选中此行。
  6. 注意要隐藏文件扩展名,请选中此行。
  7. 点击确定
  8. 然后检查文件的扩展名,如果它不是jpg而且它的png只是使用.png并且它可以工作。

答案 1 :(得分:0)

Others with non-corrupt images might have the issue that they need to add the dimensions to their images (height and width) in order for it to show.

<Image source={require('./images/image1.jpg')} style={{height:30, width:30}} />
相关问题