ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.08k stars 1.55k forks source link

image can't display in android simulator #62

Closed wzy535 closed 8 years ago

wzy535 commented 8 years ago

First thank you for your help!

Version

Tell us which versions you are using:

I can get photo ,but can't display in simulator Here is the got photo path: file:///data/user/0/com.homagou/cache/30920b79-198a-4a44-8702-6f742678ad7a.jpg and it can't display use <Image source={{uri:'data:image/jpeg;base64,file:///data/user/0/com.homagou/cache/30920b79-198a-4a44-8702-6f742678ad7a.jpg', isStatic:true}} />

or <Image soure={require('file:///data/user/0/com.homagou/cache/30920b79-198a-4a44-8702-6f742678ad7a.jpg')} />

Source code:

`export default class NewDishView extends React.Component{ constructor(props){ super(props) this.state={//file:///data/user/0/com.homagou/cache/30920b79-198a-4a44-8702-6f742678ad7a.jpg imgSource:require('../images/profiledefault.jpg') } } goBack(){ this.props.navigator.pop(); }

_upload2(){
    PhotoPicker.openPicker({
      width: 300,
      height: 400,
      cropping: true
    }).then(image => {          
      console.log(image);
      this.setState({
        imgSource:require(image.path)
      })
    });
}
render(){

    return (
        <View>
            <View style={styles.header}>

                <TouchableOpacity onPress={()=>this.goBack()} style={styles.back}>
                    <Icon style={styles.backIcon} name="chevron-left" />
                </TouchableOpacity> 

                <View style={{flex:1}}>             
                    <Text style={styles.title}>Create new dish</Text>
                </View>
            </View>

            <TouchableOpacity onPress={this._upload2.bind(this)}>
                <Text>Upload image</Text>
            </TouchableOpacity>

            <Image source={this.state.imgSource} />
            <TextInput />
        </View>
    )
}

}`

ivpusic commented 8 years ago

please check example project.

Relevant lines are: https://github.com/ivpusic/react-native-image-crop-picker/blob/master/example/app.js#L71 for saving received image to state,

and https://github.com/ivpusic/react-native-image-crop-picker/blob/master/example/app.js#L98 for displaying image

wzy535 commented 8 years ago

It works now ,Thank you very much!