【发布时间】:2020-09-18 12:45:23
【问题描述】:
我有两个功能:一个是从相机中拍照,另一个是处理该图像, 当我运行代码时,会显示以下警告:
"[未处理的承诺拒绝:TypeError: undefined is not a function (near '...ImageManipulator.manipulate...')]"
这是我的导入
import * as Permissions from 'expo-permissions'
import * as ImagePicker from 'expo-image-picker'
import * as ImageManipulator from 'expo-image-manipulator'
这里是两个函数,我还应该指出代码在我实现 processImage() 函数之前就可以工作
getImageFromCamera = async () => {
const cameraPermission = await Permissions.askAsync(Permissions.CAMERA);
const cameraRollPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (cameraPermission.status === 'granted' && cameraRollPermission.status === 'granted') {
let capturedImage = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [4, 3],
});
//If the user didn't cancel the picture
if (!capturedImage.cancelled) {
console.log(capturedImage);
this.processImage(capturedImage.uri);
}
}
}
processImage = async (imageUri) => {
try {
let processedImage = await ImageManipulator.manipulate(
imageUri,
[
{ resize: { width: 400 } }
],
{ format: 'png' }
);
} catch (error) {
Alert.alert('Failed to process the Image' )
}
console.log(processedImage);
this.setState({ imageUrl: processedImage.uri });
}
我是 React Native 和 Expo 的初学者,我无法终生识别错误,如果你们需要更多信息,请告诉我
let processedImage = await ImageManipulator.manipulate 中的承诺失败
但我不知道为什么
【问题讨论】:
-
Permissions.askAsync或ImagePicker.launchCameraAsync或ImageManipulator.manipulate可能是一个错误 - 使用 try/catch 来处理来自 await 的错误应该做的那样 -
@JaromandaX Ty 快速响应:D,在使用 try/catch 玩了一下之后,错误出现在 ImageManipulator.manipulate 中,让我更新帖子。
-
同样的错误?或者现在你得到
'Failed to process the Image' -
我收到“无法处理图像”警报
-
所以,您现在已经找到了错误所在...我不知道它是什么...也许
error参数会告诉您
标签: javascript react-native expo