LeonHeart
LeonHeart

Reputation: 561

expo camera takePictureAsync ImageManipulator

I have a snippet like this

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

Now my problem is I don't know the way how to insert ImageManipulator into this function. My purpose is after takePictureAsync(), the photo will be resized to 108x192 then this photo will be moved to documentDirectory. Many thanks

Upvotes: 3

Views: 5324

Answers (1)

LeonHeart
LeonHeart

Reputation: 561

I have found the solution, here is the code

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

Upvotes: 9

Related Questions