想要显示使用摄影机拍摄的照片

时间:2018-11-09 12:58:46

标签: react-native

我正在使用照相相机组件..很幸运,我可以成功捕获图像,但是当我捕获图像时,它会给我提供图像uri,但我的相机仍在运行。.我想当我捕获图像时,将显示捕获的图像而不是相机。我该如何做到这一点,你们可以为我提供指导吗? 这是我用于捕获图像的功能代码...

 takePicture = async function() {
if (this.camera) {
    this.camera.takePictureAsync( {skipProcessing: true}).then((capturephoto)=>{
        this.setState({photo:capturephoto.uri})
        alert(this.state.photo)
    }).then(capturephoto=>{
        FileSystem.moveAsync({
                    from: capturephoto.uri,
                     to: `${FileSystem.documentDirectory}photos/Photo_${
                         this.state.photoId
                   }.jpg`
    })
    })
    }
    }

这是我使用相机组件的渲染功能

<Container style={{ flex: 1 }}>

      <Camera style={{ flex: 1 }}  ref={ref => { this.camera = ref; }} 

   >

            </Text>
          </TouchableOpacity>
          <TouchableOpacity
            style={{
             // flex: 0.1,
              alignSelf: 'flex-end',
              alignItems: 'center',
            }}
            onPress={()=>this.takePicture()}
           >
            <Text
              style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
              {' '}Take Picture{' '}
            </Text>
          </TouchableOpacity>
        </View>
      </Camera>
    </Container>
  );
}
       }
       }

0 个答案:

没有答案
相关问题