expo camera takePictureAsync ImageManipulator

时间:2018-05-09 16:17:09

标签: react-native camera expo

我有一个这样的片段

takePicture = async function() {
        if (this.camera) {
            this.camera
                .takePictureAsync()
                .then(data => {
                    FileSystem.moveAsync({
                        from: data.uri,
                        to: `${FileSystem.documentDirectory}photos/Photo_${
                            this.state.photoId
                        }.jpg`
                    }).then(() => {
                        this.setState({
                            photoId: this.state.photoId + 1
                        });
                        Vibration.vibrate();
                    });
                });
        }
    };

现在我的问题是我不知道如何将ImageManipulator插入此功能。我的目的是在takePictureAsync()之后,照片将被调整为108x192,然后这张照片将被移动到documentDirectory。非常感谢

1 个答案:

答案 0 :(得分:5)

我找到了解决方案,这里是代码

takePicture = async function() {
        if (this.camera) {
            let photo = await this.camera.takePictureAsync();
            let resizedPhoto = await ImageManipulator.manipulate(
                photo.uri,
                [{ resize: { width: 108, height: 192 } }],
                { compress: 0, format: "jpg", base64: false }
            );
            FileSystem.moveAsync({
                from: resizedPhoto.uri,
                to: `${FileSystem.documentDirectory}photos/Photo_${
                    this.state.photoId
                }.jpg`
            });
            this.setState({ photoId: this.state.photoId + 1 });
            Vibration.vibrate();            
        }
    };