我正在尝试将使用React Native Camera库拍摄的图像发送到Camera Roll。用户按下按钮时,将触发以下功能: takePicture = async function() { if (this.camera) { const options = { quality: 0.5, base64: true } const data = await this.camera.takePictureAsync(options) CameraRoll.saveToCameraRoll(data.uri) } }我已经知道该应用程序会将图片发送到缓存文件夹,因为执行此代码后,将显示该图片的链接: takePicture = async function() { if (this.camera) { const options = { quality: 0.5, base64: true } const data = await this.camera.takePictureAsync(options) console.log(data.uri) } }调试器显示以下错误:Possible Unhandled Promise Rejection (id:0)React Native Camera: TypeError: _reactNative.default.saveToCameraRoll is not a functionCam组件的代码:import React, {Component} from 'react';import {StyleSheet, View} from 'react-native'import { RNCamera } from 'react-native-camera'import CameraRoll from 'react-native'import ActionButton from 'react-native-action-button'import Icon from 'react-native-vector-icons/Ionicons'const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center' }, button: { height: 200, justifyContent: 'flex-end', alignItems: 'center' }, actionButtonIcon: { fontSize: 20, height: 22, color: 'white', },});export default class Cam extends Component { constructor() { super() this.takePicture = this.takePicture.bind(this) } takePicture = async function() { if (this.camera) { const options = { quality: 0.5, base64: true } const data = await this.camera.takePictureAsync(options) CameraRoll.saveToCameraRoll(data.uri) } } render() { return ( <View style={styles.container}> <RNCamera ref={ref => {this.camera = ref}} style={{ flex: 1, width: '100%', position: 'relative' }}
1 回答
神不在的星期二
TA贡献1963条经验 获得超6个赞
望着这个例子说明如何使用CameraRoll :
import {
View,
Text,
TouchableHighlight,
Modal,
StyleSheet,
Button,
CameraRoll,
Image,
Dimensions,
ScrollView,
} from 'react-native'
您必须更换:
import CameraRoll from 'react-native';
经过
import { CameraRoll } from 'react-native';
(我已将其作为答案,因此可以接受并结束问题)
在您的代码中,您可以像这样相互导入:
import React, {
Component,
} from 'react';
import {
RNCamera,
} from 'react-native-camera';
import {
CameraRoll,
StyleSheet,
View,
} from 'react-native';
import ActionButton from 'react-native-action-button';
import Icon from 'react-native-vector-icons/Ionicons';
添加回答
举报
0/150
提交
取消