Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从react native Image picker中选择图像后,图像不会显示_Javascript_React Native_React Native Android_React Native Image Picker - Fatal编程技术网

Javascript 从react native Image picker中选择图像后,图像不会显示

Javascript 从react native Image picker中选择图像后,图像不会显示,javascript,react-native,react-native-android,react-native-image-picker,Javascript,React Native,React Native Android,React Native Image Picker,我正在开发一个应用程序,在其中我需要从手机上传图像,一旦我单击upload gallery显示,我就可以选择图像,但一旦选择了图像,图像就不会显示在我使用的图像容器中 我的代码 这是selectImage函数 selectImage = () => { const options = { title: 'Select Profile Picture', storageOptions: { ski

我正在开发一个应用程序,在其中我需要从手机上传图像,一旦我单击upload gallery显示,我就可以选择图像,但一旦选择了图像,图像就不会显示在我使用的图像容器中

我的代码

这是selectImage函数

selectImage = () => {
        const options = {
            title: 'Select Profile Picture',
            storageOptions: {
                skipBackup: true,
                path: 'images',
            },
        };
        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);
                Alert.alert(response.error.toString())
            } else if (response.customButton) {
                console.log('User tapped custom button: ', response.customButton);
            } else {
                //let source = { uri: response.uri };
                Alert.alert(response.uri)
                let source = { uri: 'data:image/jpeg;base64,' + response.data };
                this.setState({
                    imageSource: source,
                    data: response.data,
                });
            }
        });
    } 
这是显示代码

<Image source={this.state.imageSource} style={{ width: 200, height: 250 }} />



未引发任何错误。

设置状态后,尝试添加console.log。如果状态为空,则在更新状态时出错。如果状态中填充了所选映像的uri,请尝试重建应用程序

在设置状态后尝试添加console.log。如果状态为空,则在更新状态时出错。如果状态中填充了所选图像的uri,则尝试重建应用程序

尝试将图像源直接设置为由
ImagePicker
响应提供的
uri

Alert.alert(response.uri);
let source = { uri: response.uri };
this.setState({
  imageSource: source,
  data: response.data,
});

尝试将图像源直接设置为
ImagePicker
响应提供的
uri

Alert.alert(response.uri);
let source = { uri: response.uri };
this.setState({
  imageSource: source,
  data: response.data,
});

最后我发现了问题,这是由于react-native web swiper,我的图像容器在此内,这不支持状态的重新渲染。

最后我发现了问题,这是由于react-native web swiper,我的图像容器在此内,这不支持状态的重新渲染。

图像源已使用选定的图像值更新,我也尝试重建应用程序,但图像仍不显示。我猜状态变量未更新,是否有可能发生这种情况?尝试使用图像的高度和宽度构建视图容器,让图像高度和宽度为100%控制台图像状态并与实际图像进行验证Uri尝试宽度和高度为100%但仍然相同图像源已使用选定的图像值进行更新,我也尝试重建应用程序,但图像仍不显示我猜状态变量未得到更新,有可能发生这种情况吗?尝试使用图像的高度和宽度构建视图容器,并将图像高度和宽度设置为100%,以控制图像的状态,并使用实际图像进行验证。urii尝试使用宽度和高度设置为100%,但仍然相同