微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误:无法拍照-预览在React Native中已暂停

如何解决错误:无法拍照-预览在React Native中已暂停

我在本机上实现了相机。当我单击“捕捉”以捕获图像时,它显示错误:无法拍照-预览已暂停,请在拍照前将其恢复。我的代码如下:

<RNCamera
        ref={ref => {
          this.camera = ref;
        }}
        captureAudio={false}
        style={{flex: 1}}
        type={RNCamera.Constants.Type.back}
        androidCameraPermissionoptions={{
          title: 'Permission to use camera',message: 'We need your permission to use your camera',buttonPositive: 'Ok',buttonNegative: 'Cancel',}}>
        <Text onPress={this.takePicture}>Snap</Text>
</RNCamera>

constructor(props) {
    super(props);
    this.state = {
      takingPic: false,};
  }
  takePicture = async () => {
    if (this.camera && !this.state.takingPic) {
       
      let options = {
        quality: 0.85,base64: true,};

      this.setState({takingPic: true});

      try {
        const data = await this.camera.takePictureAsync(options);
        Alert.alert('Success',JSON.stringify(data));
      } catch (err) {
        Alert.alert('Error','Failed to take picture: ' + (err.message || err));
        return;
      } finally {
        this.setState({takingPic: false});
      }

    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。