adn*_*leb 5 javascript exp react-native
我正在使用 expo API 开发反应本机应用程序,该应用程序基本上拍摄一张图片,然后应用程序使用 ImageEditor.cropImage 裁剪它,最后将图片从缓存复制到另一个位置。代码:
takePicture = async function() {
if (this.camera) {
this.camera.takePictureAsync().then(async (data) => {
cropdata = {
offset:{x:0, y:0},
size:{width:100, height:100},
};
await ImageEditor.cropImage(
data.uri,
cropdata,
async (uri) => {
FileSystem.moveAsync({
from: uri,
to: `${FileSystem.documentDirectory}photos/Photo_${this.state.photoId}.jpg`,
}).then(() => {
this.setState({
photoId: this.state.photoId + 1,
});
Vibration.vibrate();
});
},
(error) => {
console.log(error);
}
);
});
}
};
Run Code Online (Sandbox Code Playgroud)
但显示以下错误:
[未处理的承诺拒绝:错误:位置“file:///data/user/0/host.exp.exponent/cache/ReactNative_cropped_image_574763720.jpg”不可移动。]
任何想法?
Expo\xe2\x80\x99s 文件系统模块可以复制/移动等。之前保存在 app\xe2\x80\x99s 范围中的文件(例如通过 ImagePicker 或使用 Asset.loadAsync)。ImagerEditor 是 React Native 的核心功能,它将图像保存到 Expo\xe2\x80\x99s 范围之外的文件中,因此 FileSystem 无法对此文件执行操作。更多相关内容可以在这里找到:
\n\nhttps://forums.expo.io/t/where-does-camera-takepictureasync-save-photos/6475/7
\n\n因此,ImageEditor.cropImage()
应该使用 expo ImageManipulator而不是使用它。
归档时间: |
|
查看次数: |
5514 次 |
最近记录: |