Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, NgZone } from '@angular/core';
  2. import {NavController, NavParams, LoadingController, Platform} from 'ionic-angular';
  3. import { ImghandlerProvider } from '../../providers/imghandler/imghandler';
  4. import { UserProvider } from '../../providers/user/user';
  5. import { Camera, CameraOptions } from '@ionic-native/camera';
  6. import { normalizeURL } from 'ionic-angular';
  7.  
  8. @Component({
  9.   selector: 'page-profilepic',
  10.   templateUrl: 'profilepic.html',
  11. })
  12. export class ProfilePicPage {
  13.   imgurl = "assets/images/noperfilpic.png";
  14.   moveon = true;
  15.   constructor(public navCtrl: NavController, public navParams: NavParams,
  16.               public imgservice: ImghandlerProvider, public zone: NgZone,
  17.               public userservice: UserProvider, public loadingCtrl: LoadingController,
  18.               private camera: Camera, public platform: Platform) {
  19.   }
  20.  
  21.   ionViewDidLoad() {
  22.   }
  23.  
  24.   chooseimage() {
  25.     let loader = this.loadingCtrl.create({
  26.       content: 'Please wait'
  27.     });
  28.     loader.present();
  29.     this.imgservice.uploadimage().then((uploadedurl: any) => {
  30.       loader.dismiss();
  31.       this.zone.run(() => {
  32.         console.log(uploadedurl);
  33.         this.imgurl = uploadedurl;
  34.         this.moveon = false;
  35.       })
  36.     })
  37.   }
  38.  
  39.   updateproceed() {
  40.     let loader = this.loadingCtrl.create({
  41.       content: 'Please wait'
  42.     });
  43.     //loader.present();
  44.     this.userservice.updateimage(this.imgurl).then((res: any) => {
  45.       //loader.dismiss();
  46.       if (res.success) {
  47.         //this.navCtrl.setRoot('TabsPage');
  48.       }
  49.       else {
  50.         alert(res);
  51.       }
  52.     })
  53.   }
  54.   /*private openGallery (): void {
  55.     let cameraOptions = {
  56.       sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
  57.       destinationType: this.camera.DestinationType.FILE_URI,
  58.       quality: 80,
  59.       targetWidth: 400,
  60.       targetHeight: 400,
  61.       encodingType: this.camera.EncodingType.JPEG,
  62.       correctOrientation: true
  63.     }
  64.  
  65.     this.camera.getPicture(cameraOptions)
  66.       .then(file_uri => this.imgurl = file_uri,
  67.         err => console.log(err));
  68.   }*/
  69.  
  70.   takePicture() {
  71.  
  72.     const options: CameraOptions = {
  73.       quality: 100,
  74.       destinationType: this.platform.is('ios') ? this.camera.DestinationType.FILE_URI : this.camera.DestinationType.DATA_URL,
  75.       encodingType: this.camera.EncodingType.JPEG,
  76.       mediaType: this.camera.MediaType.PICTURE
  77.     }
  78.  
  79.     this.camera.getPicture(options).then((imageData) => {
  80.  
  81.       let base64Image = null;
  82.  
  83.       //get photo from the camera based on platform type
  84.       if (this.platform.is('ios'))
  85.         base64Image = normalizeURL(imageData);
  86.       else
  87.         base64Image = "data:image/jpeg;base64," + imageData;
  88.  
  89.       //add photo to the array of photos
  90.       this.imgurl =base64Image;
  91.  
  92.     }, (error) => {
  93.       console.debug("Unable to obtain picture: " + error, "app");
  94.       console.log(error);
  95.     });
  96.   }
  97.  
  98.   openGallery() {
  99.     let cameraOptions = {
  100.       sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
  101.       destinationType: this.camera.DestinationType.FILE_URI,
  102.       quality: 100,
  103.       targetWidth: 1000,
  104.       targetHeight: 1000,
  105.       encodingType: this.camera.EncodingType.JPEG,
  106.       correctOrientation: true
  107.     };
  108.  
  109.     this.camera.getPicture(cameraOptions).then((file_uri) => {
  110.  
  111.       //add photo to the array of photos
  112.       this.imgurl=normalizeURL(file_uri);
  113.  
  114.     }, (error) => {
  115.       console.debug("Unable to obtain picture: " + error, "app");
  116.       console.log(error);
  117.     });
  118.   }
  119.  
  120.   /*proceed() {
  121.     this.navCtrl.setRoot('TabsPage');
  122.   }*/
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement