saveToCameraRoll不是函数

我正在尝试将使用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 function

Cam组件的代码:


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'

          }}

     

小唯快跑啊
浏览 186回答 1
1回答

神不在的星期二

望着这个例子说明如何使用CameraRoll :import {&nbsp; View,&nbsp; Text,&nbsp; TouchableHighlight,&nbsp; Modal,&nbsp; StyleSheet,&nbsp; Button,&nbsp; CameraRoll,&nbsp; Image,&nbsp; Dimensions,&nbsp; ScrollView,} from 'react-native'您必须更换:import CameraRoll from 'react-native';经过import { CameraRoll } from 'react-native';(我已将其作为答案,因此可以接受并结束问题)在您的代码中,您可以像这样相互导入:import React, {&nbsp; Component,} from 'react';import {&nbsp;&nbsp; &nbsp;RNCamera,} from 'react-native-camera';import {&nbsp; CameraRoll,&nbsp; StyleSheet,&nbsp; View,} from 'react-native';import ActionButton from 'react-native-action-button';import Icon from 'react-native-vector-icons/Ionicons';
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript