世博会相机 takePictureAsync ImageManipulator
Posted
技术标签:
【中文标题】世博会相机 takePictureAsync ImageManipulator【英文标题】:expo camera 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.documentDirectoryphotos/Photo_$
this.state.photoId
.jpg`
).then(() =>
this.setState(
photoId: this.state.photoId + 1
);
Vibration.vibrate();
);
);
;
现在我的问题是我不知道如何将 ImageManipulator 插入此函数。我的目的是在 takePictureAsync() 之后,将照片调整为 108x192,然后将这张照片移动到 documentDirectory。非常感谢
【问题讨论】:
【参考方案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.documentDirectoryphotos/Photo_$
this.state.photoId
.jpg`
);
this.setState( photoId: this.state.photoId + 1 );
Vibration.vibrate();
;
【讨论】:
如果我错了,请纠正我,但这会导致错误,photo.uri 可能未定义。 拍照后有照片对象返回,所以uri不能为undefined以上是关于世博会相机 takePictureAsync ImageManipulator的主要内容,如果未能解决你的问题,请参考以下文章