使用 expo-image-picker 时,我的 Android 手机上的 expo 客户端应用程序在拍照后崩溃。
这是我的代码:
import * as ImagePicker from "expo-image-picker";
const takeImageHandler = async () => {
const hasPermission = await verifyPermissions();
if (!hasPermission) {
return;
}
const image = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [16, 9],
quality: 0.5,
});
console.log(image);
};
尝试使用此代码
const openCamera = async () => {
// Ask the user for the permission to access the camera
const permissionResult = await ImagePicker.requestCameraPermissionsAsync();
if (permissionResult.granted === false) {
alert("You've refused to allow this appp to access your camera!");
return;
}
const result = await ImagePicker.launchCameraAsync();
// Explore the result
console.log(result);
if (!result.cancelled) {
setPickedImagePath(result.uri);
console.log(result.uri);
}
}
并确保您已使用 npm 最新版本安装了图像选择器 必须再次检查你的 package.json 是否安装了 expo 图像选择器
我今天在使用 expo-image-picker 库时遇到了同样的问题。我能够打开相机并拍摄图像,但当我尝试通过单击刻度线保存图像时,应用程序会重新加载。因此,我在另一部手机上进行了测试,效果非常好。
我测试的第一部手机是旧的 Android 手机,第二部是较新的 Android 手机,所以我建议您使用较新/最新的型号。