【问题标题】:expo camera takePictureAsync ImageManipulator世博会相机 takePictureAsync ImageManipulator
【发布时间】:2018-10-19 20:06:31
【问题描述】:

我有一个这样的sn-p

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。非常感谢

【问题讨论】:

    标签: react-native camera expo


    【解决方案1】:

    我找到了解决办法,这里是代码

    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();            
            }
        };
    

    【讨论】:

    • 如果我错了,请纠正我,但这会导致错误,photo.uri 可能未定义。
    • 拍照后有照片对象返回,所以uri不能为undefined
    猜你喜欢
    • 1970-01-01
    • 2019-01-28
    • 2019-11-14
    • 2021-05-27
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 2022-07-21
    相关资源
    最近更新 更多