选择不起作用后的博览会图像预览

时间:2021-04-26 12:06:08

标签: react-native expo

如果用户选择图像,那么我得到本地 Uri。如果我创建一个带有源 uri 的 Image 组件并将本地 uri 放在那里,它就不起作用。但为什么?

Home.js

  const pickImage = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.All,
      allowsEditing: true,
      aspect: [1, 1],
      quality: 1
    });
    
    if(!result.cancelled) {
      let localUri = result.uri;
      let filename = localUri.split('/').pop();

      let match = /\.(\w+)$/.exec(filename);
      let type = match ? `image/${match[1]}` : `image`;


      setImagePreview(localUri);
    }
  };

还有 Home.js 但其他代码片段:

<Image source={{uri: imagePreview}}/>

€:这是本地 uri:

file:/data/user/0/host.exp.exponent/cache/ExperienceData/UNVERIFIED-192.168.0.54-gamezone/ImagePicker/b5c20467-4ad1-4bdf-aa74-8aad82e2c075.jpg

1 个答案:

答案 0 :(得分:1)

替换这一行

<Image source={{uri: imagePreview}}/>

有了这个

<Image source={{uri: imagePreview}} style={{ width: 200, height: 200 }} />

您需要向Dimensions提供image