React Native:将映像加载为Base64

时间:2019-09-09 09:11:20

标签: android ios react-native require react-native-camera

虽然对可以在模拟器中运行的react-native-camera模块进行了简单的模拟,但我在使用require时遇到了问题。

我正在使用它来加载模拟器图像:

const viewfinderImage = require('../images/simulator_image.jpg')

这可行:

this.viewfinder = React.createElement(Image, {style: this.props.style, source: viewfinderImage}, null);

这不是:

 async takePictureAsync() {
     console.log("Viewfinder image",viewfinderImage);//this.viewfinder.source);
     return viewfinderImage;//this.viewfinder.source
 }

有什么方法可以使takePictureAsync()在iOS和Android上返回取景器图像?还是唯一将其静态定义为Base64文本文件的选项?

import React, { Component } from 'react';
import {
    View,
    Image,
} from "react-native";

const viewfinderImage = require('../images/simulator_image.jpg');

export class RNCamera extends Component {
    static Constants = {
        Type: {
            back: 'back'
        }
    }

    constructor(props) {
        super(props);
        this.state = {
            showCam: true,
            permissions: true,
            isAuthorized: true,
        };
    }

    async takePictureAsync() {
        console.log("Viewfinder image",viewfinderImage);//this.viewfinder.source);
        return viewfinderImage;//this.viewfinder.source
    }

    render() {
        this.viewfinder = React.createElement(Image, {style: this.props.style, source: viewfinderImage}, null);
        return(
            <View
                style={this.props.style}
            >
                { this.state.showCam === true && this.state.permissions === true && this.viewfinder }
                { this.state.showCam === true && this.state.permissions !== true && this.props.notAuthorizedView }
            </View>
        )
    }
}

0 个答案:

没有答案