2017-11-10 62 views
0

我想从我的电脑文件中显示图像。但是,它不会出现。我做了调试的一个小一点,发现当我把我的目录是:无法找到图像的相对/本地目录 - 反应本机

source={{uri:'http://www.telegraph.co.uk/content/dam/Travel/galleries/travel/activityandadventure/The-worlds-most-beautiful-mountains/mountains-fitzroy_3374108a.jpg'}} 

它显示在屏幕中央的图像,我希望它是。我不想使用网络地址,我想使用相关的地址。所以我用这个:

source={{uri:'/./pictures/m.jpg'}} 

当我这样做,它出现没有图像或错误。 如何让图像出现在相对目录中? 这里是我的所有代码:

import React, { Component } from 'react'; 
import { Button,Alert, TouchableOpacity,Image, Dimensions } from 'react-native' 

import { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View, 
} from 'react-native'; 

class Project extends Component { 
    render() { 
    return (
     <View style={{backgroundColor: '#375D81', flex: 1}}> 

     <View style = {styles.container}> 
      <Image source={{uri: './pictures/Blur.png/'}} style={{ resizeMode: 'cover', width: 100, height: 100 }}/> 
      <TouchableOpacity style = {styles.buttonText1} onPress={() => { Alert.alert('You tapped the button!')}}> 
      <Text style={styles.text}> 
       Button 1 
      </Text> 
      </TouchableOpacity> 

      <TouchableOpacity style = {styles.buttonText2} onPress={() => { Alert.alert('You tapped the button!')}}> 
      <Text style= {styles.text}> 
       Button 2 
      </Text> 
      </TouchableOpacity> 

     </View> 
     </View> 
    ); 
    } 
} 

这里是我的文件夹: enter image description here 预先感谢您。

回答

0

当使用本地目录,最好是使用require功能,如:

<Image source={{require('./pictures/Blur.png/')}} style={{ resizeMode: 'cover', width: 100, height: 100 }}/>