相机拍摄后无法打印照片

时间:2018-05-14 09:56:48

标签: react-native

我正在尝试制作要在个人资料页面上打印的照片。虽然我得到了照片的uri,但没有打印出来。我正在使用camerja example of this page

      <TouchableOpacity onPress={this.shotPhoto.bind(this)}>
        <Image source={this.props.userpicture != null ? this.props.userpicture : require('../../images/resimyok.png')} />
        <Text>Shot a Photo</Text>
      </TouchableOpacity>

返回的photo.uri是

文件:///data/user/0/host.exp.exponent/files/ExperienceData/%2540programci.yilmaz%252Fkpbduser/photos/Photo_2.jpg

我收到的警告信息是:

Warning: Failed prop type: Invalid prop `source` supplied to `Image`.

Before getting image url from camera the profile page

After getting image url from camera the profile page

图片uri返回的页面

takePicture = async function() {
if (this.camera) {
  const options = { quality: 0.5, base64: true };

  this.camera.takePictureAsync().then(data => {
    FileSystem.moveAsync({
      from: data.uri,
      to: `${FileSystem.documentDirectory}photos/Photo_${this.state.photoId}.jpg`,
    }).then(() => {
      this.setState({
        photoId: this.state.photoId + 1,
      });
      Vibration.vibrate();
      Actions.hesabim({userpicture: `${FileSystem.documentDirectory}photos/Photo_${this.state.photoId}.jpg`});
    });
  });
}

};

2 个答案:

答案 0 :(得分:1)

请重写您的代码,必须在网址请求传递时间上添加 uri

 <TouchableOpacity onPress={this.shotPhoto.bind(this)}>
    <Image source={this.props.userpicture != null ? uri:this.props.userpicture : require('../../images/resimyok.png')} />
    <Text>Shot a Photo</Text>
  </TouchableOpacity>

答案 1 :(得分:0)

<Image style={{height: 200, width: 150}} source={{uri: this.props.userpicture} != null ? {uri: this.props.userpicture} : require('../../images/resimyok.png') } />

解决了我的问题,虽然这次没有显示默认图像。

相关问题