react-native - 错误:无法拍照 - 预览在 React Native 中暂停
问题描述
我在 react-native 中实现了相机。当我单击 Snap 捕获图像时,它显示错误:无法拍照 - 预览已暂停,在拍照之前恢复它。我的代码如下:
<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});
}
}
解决方案
推荐阅读
- python - 为什么 PySpark 在创建 SparkSession 时找不到 spark-submit?
- javascript - Array.flat() 与扩展运算符将多个数组扁平化为一个
- python - Django 过滤多对多
- python - 如何让用户根据我创建的字典输入电话号码并让他们以 XXX-XXX-XXXX 格式输入键或值?
- yii - 在 main.php 文件中使用 url::to()
- javascript - 仅向访问特定页面的用户显示内容?
- php - 在不同的选项卡中重用 Blade 模板
- 3d - KinematicBody.move_and_slide() 只能从实例调用
- linux-kernel - UIO驱动——理解实现逻辑
- c++ - C++ 在函数之间传递变量