我正在尝试集成react-native-image-picker并且我能够成功安装它。现在,当我尝试从日志中的图库中选择图像时,它确实显示我的 imageSource 具有价值但它不显示。我目前正在 iOS 模拟器上运行它。下面是我的代码
import ImagePicker from "react-native-image-picker";
const options = {
title: "Select a photo",
takePhotoButtonTitle: "Take a photo",
chooseFromLibraryButtonTitle: "Choose from gallery",
quality: 1
};
constructor(props) {
super(props);
this.state = { imageSource: null };
}
addImage = () => {
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else {
const source = { uri: response.uri };
this.setState({
imageSource: source,
});
console.log("Imagesource=" + JSON.stringify(source));
}
});
}
render() {
return (
<View style={styles.container}>
<Image source={this.state.imageSource} />
</View>
);
}
控制台日志确实打印了我从图库中选择的图像的路径,但它只是不显示。我在 iPad 上横向运行它。任何帮助表示赞赏。