RN:如何将uri用于本地图像文件源

时间:2019-06-30 06:12:11

标签: react-native

以下是RN documentImage的示例:

import React, { Component } from 'react';
import { AppRegistry, View, Image } from 'react-native';

export default class DisplayAnImage extends Component {
  render() {
    return (
      <View>
        <Image
          source={require('/react-native/img/favicon.png')}
        />
      </View>
    );
  }
}

对于本地图像文件,它使用source = {require('path-to-image-file')}。我的渲染代码如下:

     <View>
        <Image
          style={{width:150, height:100,borderRadius:13,margin:3, resizeMode:'cover'}}
          source={require("./image1.jpg")}  //<<tested working for image file resides in the same subdir of component
         />
      </View> 

我正在尝试将uri: ""的格式转换为source。这是尝试的字符串列表,不适用于位于组件相同子目录中的本地文件image1.jpg

source={{uri: "./image1.jpg"}}
source={{uri: "/image1.jpg"}}
source={{uri: "image1.jpg"}}
source={{uri: "file:///image1.jpg"}}
source={{uri: "file: //image1.jpg"}}
source={{uri: "file:/image1.jpg"}}
source={{uri: "file: image1.jpg"}} //<<== syntax error 

uri源的正确格式是什么?

0 个答案:

没有答案