uploadImage(){ var options = { title: '选择图片', cancelButtonTitle: '取消', takePhotoButtonTitle: '拍照', chooseFromLibraryButtonTitle: '从图库中获取', maxWidth: 1000, maxHeight: 1000, aspectX: 1, aspectY: 1, quality: 1, allowsEditing: false }; ImagePickerManager.showImagePicker(options, (response) => { if (response.didCancel) { ///console.log('User cancelled image picker'); } else if (response.error) { //console.log('ImagePickerManager Error: ', response.error); ToastAndroid.show('出现未知错误',ToastAndroid.SHORT); } else { const source = {uri:"file://"+response.path, isStatic: true}; var files=[{ uri:source.uri, name:source.uri.split('/').pop() }]; fileName=files[0].name; this.uploadFun(files); } }); }
_uploadIdBack: function () { var options = { title: '选择身份证背面照', cancelButtonTitle: '取消', takePhotoButtonTitle: '拍照', chooseFromLibraryButtonTitle: '从手机相册选取', cameraType: 'back', mediaType: 'photo', allowsEditing: false, noData: false, storageOptions: { skipBackup: true, path: 'images' } }; ImagePickerManager.showImagePicker(options, (response) => { if (response.didCancel) { console.log('User cancelled image picker'); } else if (response.error) { console.log('ImagePickerManager Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { const source = {uri: response.uri.replace('file://', ''), isStatic: true}; const sourceData = 'data:image/jpeg;base64,' + response.data; this.setState({ idBackSource: source, idBackSourceData: sourceData }); } }); },
export const pickImage = () => new Promise((resolve, reject) => { ImagePickerManager.showImagePicker(options, (response) => { if (response.didCancel) { const error = new Error(); error.message = 'User cancelled image picker'; error.response = response; reject(error); } else if (response.error) { const error = new Error(); error.message = 'ImagePickerManager Error'; error.response = response; reject(error); } else { const uri = Platform.OS === 'android' ? response.uri : response.uri.replace('file://', ''); const source = { uri, isStatic: true }; const image = { source, data: response.data }; resolve(image); } }); });
showImagePicker: function() { var options = { title: 'Select Photo', cancelButtonTitle: 'Cancel', takePhotoButtonTitle: 'Take Photo...', chooseFromLibraryButtonTitle: 'Choose from Library...', returnBase64Image: false, returnIsVertical: false }; ImagePickerManager.showImagePicker(options, (response) => { var source = null; if(response.didCancel) { return; } else { source = { uri: 'data:image/jpeg;base64,' + response.data, isStatic: true }; this.setState({ imgSource: source, unselected: false }); } }); },
selectPhotoTapped() { let options = { title: '选择照片', cancelButtonTitle: '取消', takePhotoButtonTitle: '拍照', chooseFromLibraryButtonTitle: '从相册选择', quality: 0.5, maxWidth: 300, maxHeight: 300, storageOptions: { skipBackup: true } }; ImagePickerManager.showImagePicker(options, (response) => { if (response.didCancel) { console.log('User cancelled photo picker'); } else if (response.error) { console.log('ImagePickerManager Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { // You can display the image using either: let source = 'data:image/jpeg;base64,' + response.data; this.setState({ showLogo: response.data, fightpic: source, }); } }); }
//修改头像 setAvator(){ let that = this; ImagePickerManager.showImagePicker(options, (response) => { const formData = new FormData(); var photo = { uri: response.uri, type: 'image/jpeg', name: 'avactor.jpg', }; formData.append('id',this.state.userId); formData.append('pic',photo); const opts = { method:'POST', headers:{ "Content-Type": "multipart/form-data" }, body:formData } fetch(ServiceURL.baseUrl + ServiceURL.changeAvatorUrl,opts) .then((response) => response.text()) .then((responseText) => { let res = JSON.parse(responseText); if(res.Status === true){ that.setState({ avator:res.filename }); } }) .catch(function(err){ alert(err); }); }); }
takePicture() { var that = this; ImagePickerManager.showImagePicker(cameraOptions, (response) => { console.log('Response = ', response); if (response.didCancel) { console.log('User cancelled image picker'); } else if (response.error) { console.log('ImagePickerManager Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { // You can display the image using either data: const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true}; // uri (on iOS) // const source = {uri: response.uri.replace('file://', ''), isStatic: true}; // uri (on android) //const source = {uri: response.uri, isStatic: true}; that.setState({ image: source.uri }); } }); }
takePicture() { let time = moment(); // pega a Imagem ImagePickerManager.showImagePicker(this.cameraOptions, (response) => { // se o usuário cancelou, notifica na tela if(response.didCancel) { ToastAndroid.show('Cancelado.', ToastAndroid.SHORT); this.setState({ isFetching: false }); return; } // se deu erro, notifica na tela if(response.error) { ToastAndroid.show('Erro ao receber a foto', ToastAndroid.SHORT); console.log(error); this.setState({ isFetching: false }); return; } this.setState({ image: { uri: response.uri, data: 'data:image/jpeg;base64,' + response.data } }); // action de bater o Ponto this.props.changeImageUser( this.props.user.id, { uri: response.uri, data: 'data:image/jpeg;base64,' + response.data } , this.state); this.setState({ isFetching: false }); this.editClose(); }); }
selectPhotoTapped() { let options = { title: '选择照片', cancelButtonTitle: '取消', takePhotoButtonTitle: '拍照', chooseFromLibraryButtonTitle: '从相册选择', maxWidth: 300, maxHeight: 300, quality: 1, allowsEditing: true, storageOptions: { skipBackup: true } }; ImagePickerManager.showImagePicker(options, (response) => { // console.log('Response = ', response); if (response.didCancel) { console.log('User cancelled photo picker'); } else if (response.error) { console.log('ImagePickerManager Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { // You can display the image using either: let source = 'data:image/jpeg;base64,' + response.data; // let source = {uri: response.uri.replace('file://', ''), isStatic: true}; // let data = this.state.userdata; //这里出发了上个界面的componentWillReceiveProps 传入了新的props // data['UserWebPicture'] = data //这里就是这里,搞好了可就爽了 this.setState({ value: response.data, iconText: '确定', imgSrc: source, }); } }); }
selectPhotoTapped() { const options = { title: 'Photo Picker', takePhotoButtonTitle: 'Take Photo...', chooseFromLibraryButtonTitle: 'Choose from Library...', quality: 1, maxWidth: 3000, maxHeight: 3000, storageOptions: { skipBackup: true }, allowsEditing: true }; ImagePickerManager.showImagePicker(options, (response) => { console.log('Response = ', response); if (response.didCancel) { console.log('User cancelled photo picker'); } else if (response.error) { console.log('ImagePickerManager Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { // You can display the image using either: //const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true}; var source; if (Platform.OS === 'android') { source = {uri: response.uri, isStatic: true}; } else { source = {uri: response.uri.replace('file://', ''), isStatic: true}; } this.setState({ avatarSource: source }); } }); }
_onPressLoadCamera() { var options = { title: '选择头像获取方式', cancelButtonTitle: '结束', takePhotoButtonTitle: '照相机', chooseFromLibraryButtonTitle: '相册', cameraType: 'back', mediaType: 'photo', videoQuality: 'high', maxWidth: 200, maxHeight: 200, aspectX: 2, aspectY: 1, quality: 1, angle: 0, allowEditing: false, noData: false, storageOpations: { skipBackup: true, path: 'images' } }; ImagePickerManager.showImagePicker(options,(response) => { if(response.error) { console.log('ImagePickerManager Error: ',response.error); }else { //const source = {uri: 'data:image/jpeg;base64,' + response.data,isStatic: true}; // uri (on iOS) //const source = {uri: response.uri.replace('file://', ''), isStatic: true}; //uri (on android) const source = {uri: response.uri, isStatic: true}; this.setState({ sourceUrl: source, }); } }) }
takePicture() { var _this = this; this.props.actPushing(); var options = { title: 'Selecciona una foto', // specify null or empty string to remove the title cancelButtonTitle: 'Cancelar', takePhotoButtonTitle: 'Tomar foto...', // specify null or empty string to remove this button chooseFromLibraryButtonTitle: 'Escoger de libería...', // specify null or empty string to remove this button cameraType: 'back', // 'front' or 'back' mediaType: 'photo', // 'photo' or 'video' videoQuality: 'high', // 'low', 'medium', or 'high' maxWidth: 2000, // photos only maxHeight: 2000, // photos only aspectX: 2, // android only - aspectX:aspectY, the cropping image's ratio of width to height aspectY: 1, // android only - aspectX:aspectY, the cropping image's ratio of width to height quality: 0.5, // 0 to 1, photos only angle: 0, // android only, photos only allowsEditing: false, // Built in functionality to resize/reposition the image after selection noData: true, // photos only - disables the base64 `data` field from being generated (greatly improves performance on large photos) storageOptions: { // if this key is provided, the image will get saved in the documents directory on ios, and the pictures directory on android (rather than a temporary directory) skipBackup: true, // ios only - image will NOT be backed up to icloud path: 'images' // ios only - will save image at /Documents/images rather than the root } }; /** * The first arg will be the options object for customization, the second is * your callback which sends object: response. * * See the README for info about the response */ ImagePickerManager.showImagePicker(options, (response) => { console.log('Response = ', response); if (response.didCancel) { _this.props.actPushingDone(); console.log('User cancelled image picker'); } else if (response.error) { _this.props.actPushingDone(); console.log('ImagePickerManager Error: ', response.error); } else { // You can display the image using either data: _this.props.actPushing(); var imageuri = response.uri; shareLinkContent.photos[0].imageUrl=imageuri; console.log(shareLinkContent); NetInfo.fetch().done((reach) => { console.log(reach); //Subir fotos solo por wifi if("WIFI"==reach||"wifi"==reach||"CELL"==reach||"cell"==reach||"MOBILE"==reach||"mobile"==reach){ console.log('connected to the internet!') ShareDialog.canShow(shareLinkContent).then( function(canShow) { if (canShow) { return ShareDialog.show(shareLinkContent); }else{ console.log("No se pudo compartir"); _this.submitSelfie(imageuri); } } ).then( function(result) { if (result.isCancelled) { console.log('Share cancelled'); } else { _this.submitSelfie(imageuri); } }, function(error) { console.log("Error al compartir "+error); console.log("Error al compartir "+imageuri); _this.submitSelfie(imageuri); } ); } else { console.log("no hay internet"); _this.submitSelfie(imageuri); } }); } }); }
addAttach(){ var options = { title: '选择封面', // specify null or empty string to remove the title cancelButtonTitle: '取消', takePhotoButtonTitle: '拍照', // specify null or empty string to remove this button chooseFromLibraryButtonTitle: '从相册中选择', // specify null or empty string to remove this button customButtons: { // 'Choose Photo from Facebook': 'fb', // [Button Text] : [String returned upon selection] }, cameraType: 'front', // 'front' or 'back' mediaType: 'photo', // 'photo' or 'video' videoQuality: 'high', // 'low', 'medium', or 'high' durationLimit: 10, // video recording max time in seconds maxWidth: 100, // photos only maxHeight: 100, // photos only aspectX: 2, // android only - aspectX:aspectY, the cropping image's ratio of width to height aspectY: 1, // android only - aspectX:aspectY, the cropping image's ratio of width to height quality: 0.2, // 0 to 1, photos only angle: 0, // android only, photos only allowsEditing: true, // Built in functionality to resize/reposition the image after selection noData: false, // photos only - disables the base64 `data` field from being generated (greatly improves performance on large photos) storageOptions: { // if this key is provided, the image will get saved in the documents directory on ios, and the pictures directory on android (rather than a temporary directory) skipBackup: true, // ios only - image will NOT be backed up to icloud path: 'images' // ios only - will save image at /Documents/images rather than the root } }; /** * The first arg will be the options object for customization, the second is * your callback which sends object: response. * * See the README for info about the response */ ImagePickerManager.showImagePicker(options, (response) => { console.log('Response = ', response); if (response.didCancel) { console.log('User cancelled image picker'); } else if (response.error) { console.log('ImagePickerManager Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { // You can display the image using either data: const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true}; // // uri (on iOS) // const source = {uri: response.uri.replace('file://', ''), isStatic: true}; // // uri (on android) // const source = {uri: response.uri, isStatic: true}; this.setState({ attaches: this.state.attaches + source }); } }); }
allowsEditing: true }; ImagePickerManager.launchCamera(options, (response) => { console.log('Response = ', response); if (response.didCancel) { console.log('User cancelled photo picker'); } else if (response.error) { console.log('ImagePickerManager Error: ', response.error); } else if (response.customButton) { console.log('User tapped custom button: ', response.customButton); } else { // You can display the image using either: const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true}; // const source = {uri: response.uri.replace('file://', ''), isStatic: true}; var resData = response.data var imageData = resData.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/\f/g, "").replace(/=/g, ""); var imagereplaced = imageData.replace(/=/g, ""); var obj = "data:image/jpeg;base64," + imagereplaced; var objJson = JSON.stringify({"obj": obj}) this.goNext2(objJson, source, marker); } }); }, grabUserRequests(inputUID) {