我有 3 张图片,我希望用户点击它们打开图片选择器(单独)
我使用以下图片选择器:
import * as ImagePicker from 'expo-image-picker';
我使用以下代码(文档中的标准)
//im trying to set a default image before the user can click on the image itself
// which should open up the imager picker and then replace this image
const [image, setImage] = useState(require('../../assets/myimage.jpg'));
const pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
console.log(result);
if (!result.cancelled) {
setImage(result.uri);
}
};
我像这样调用函数:
<ScrollView horizontal={true} showsHorizontalScrollIndicator={false}>
<TouchableOpacity style={styles.button} onPress={pickImage}>
{image && <Image source={{ uri: image }} style={styles.image} />}
</TouchableOpacity>
<Image style={styles.image} source = {require('../../assets/image1.jpg')} />
<Image style={styles.image} source = {require('../../assets/image2.jpg')} />
</ScrollView>
我得到以下信息: