import ImagePicker from 'react-native-image-picker';
const options = {
title: 'Select Image',
takePhotoButtonTitle:'take a photo',
chooseFromlibraryButtonTitle:'choose from gallery',
quality:1
};
class Upload extends Component <{}>{
static navigationOptions = { header: null }
constructor(){
super()
this.state ={
ImageSource:null
}
}
selectPhoto(){
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 {
let source = { uri: response.uri };
this.setState({
ImageSource: source,
});
}
});
}
答案 0 :(得分:1)
您是否正在为Android / iOS /两者开发?看来您必须为iOS指定mediaType={mixed}
,并且必须指定是要查看Android的视频还是图像。
答案 1 :(得分:0)
你在这里
ImagePicker.showImagePicker({
title: 'Choose Image or Video',
customButtons: [{ name: 'image', title: 'Take a Photo' },{ name: 'video', title: 'Take a Video' }],
chooseFromLibraryButtonTitle: null,
takePhotoButtonTitle: null,
}, (res) => {
if(res.customButton ){
ImagePicker.launchCamera({
mediaType: res.customButton,
videoQuality: 'high',
quality: 1,
}, (response) => {
// Same code as in above section!
});
}
});