我正在使用react-native-image-picker来加载照片。这似乎对于从相机胶卷中取出的照片效果很好,但如果用户选择拍照,响应中没有数据,只有一个空字符串。
我正在使用这些选项:
{
title: 'Upload Photo',
cancelButtonTitle: 'Cancel',
takePhotoButtonTitle: 'Take Photo...',
chooseFromLibraryButtonTitle: 'Choose from Library...',
noData: false,
mediaType: 'photo',
quality: 0.2,
}
Run Code Online (Sandbox Code Playgroud)
并启动图像选择器:
UIImagePickerManager.showImagePicker(options, (response) => {
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
response.data对于从相机胶卷中挑选的图像来说效果很好,但是当用相机拍摄新图像时会给我一个空字符串。
是什么赋予了?
小智 0
如果你想使用数据(noData:false)显示图像,请使用以下命令:
UIImagePickerManager.showImagePicker(options, response => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = {uri: 'data:image/jpeg;base64,' + response.data};
this.setState({
avatarSource: source,
});
}
});
Run Code Online (Sandbox Code Playgroud)
并设置图像源的 avatarSource 状态