React Native Expo相机无法正确查看拍摄的照片

时间:2019-05-03 22:15:50

标签: react-native expo

我正在尝试查看通过摄影机拍摄的照片,但是在图像标签中设置uri后,我会出现灰屏。我已经尝试过使用uri和base64 uri,但两者都给我相同的结果

相机组件

 <Camera style={{ flex: 1 }}
        ref={(ref) => { this.camera = ref }}
        type={this.state.cameraType}
        flashMode={this.state.cameraFlash}
      >
        <View>
          <IconButton
            buttonStyle={styles.topLeft}
            onpress={() => Actions.pop()}
            name="arrow-back"
            size={40}
            color="#fff"
          />

          <View style={styles.cameraOptions}>


            <IconButton
              buttonStyle={styles.cameraOptionSpacing}
              onpress={this.takePicture}
              name='photo-library'
              size={40}
              color="#fff"
            />



          </View>
        </View>
      </Camera>


拍照功能并将uri设置为状态

async takePicture() {
    if (this.camera) {
      // setting photo options
      const options = {
        quality: 0,
        base64: false,
        fixOrientation: true,
        exif: true
      };

      //  Tell camera to take picture
      await this.camera.takePictureAsync(options).then(data => {
        console.log(data);
        //  set picture in state
        this.setState({ path: data.uri })
      });
    }
  };

我要在其中显示图像的图像标签



        <Image
          source={{ uri: this.state.path }}
          style={styles.preview}
        />


0 个答案:

没有答案