2017-11-10 59 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 }}/>