React native 世博相机拍摄图片同步图像操纵器
我有这样一个片段React native 世博相机拍摄图片同步图像操纵器,react-native,camera,expo,React Native,Camera,Expo,我有这样一个片段 takePicture = async function() { if (this.camera) { this.camera .takePictureAsync() .then(data => { FileSystem.moveAsync({ from: data.uri,
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。非常感谢我找到了解决方案,下面是代码
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可能未定义。拍照后,有一个photo对象返回,因此无法未定义uri