Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, NgZone } from '@angular/core';
- import {NavController, NavParams, LoadingController, Platform} from 'ionic-angular';
- import { ImghandlerProvider } from '../../providers/imghandler/imghandler';
- import { UserProvider } from '../../providers/user/user';
- import { Camera, CameraOptions } from '@ionic-native/camera';
- import { normalizeURL } from 'ionic-angular';
- @Component({
- selector: 'page-profilepic',
- templateUrl: 'profilepic.html',
- })
- export class ProfilePicPage {
- imgurl = "assets/images/noperfilpic.png";
- moveon = true;
- constructor(public navCtrl: NavController, public navParams: NavParams,
- public imgservice: ImghandlerProvider, public zone: NgZone,
- public userservice: UserProvider, public loadingCtrl: LoadingController,
- private camera: Camera, public platform: Platform) {
- }
- ionViewDidLoad() {
- }
- chooseimage() {
- let loader = this.loadingCtrl.create({
- content: 'Please wait'
- });
- loader.present();
- this.imgservice.uploadimage().then((uploadedurl: any) => {
- loader.dismiss();
- this.zone.run(() => {
- console.log(uploadedurl);
- this.imgurl = uploadedurl;
- this.moveon = false;
- })
- })
- }
- updateproceed() {
- let loader = this.loadingCtrl.create({
- content: 'Please wait'
- });
- //loader.present();
- this.userservice.updateimage(this.imgurl).then((res: any) => {
- //loader.dismiss();
- if (res.success) {
- //this.navCtrl.setRoot('TabsPage');
- }
- else {
- alert(res);
- }
- })
- }
- /*private openGallery (): void {
- let cameraOptions = {
- sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
- destinationType: this.camera.DestinationType.FILE_URI,
- quality: 80,
- targetWidth: 400,
- targetHeight: 400,
- encodingType: this.camera.EncodingType.JPEG,
- correctOrientation: true
- }
- this.camera.getPicture(cameraOptions)
- .then(file_uri => this.imgurl = file_uri,
- err => console.log(err));
- }*/
- takePicture() {
- const options: CameraOptions = {
- quality: 100,
- destinationType: this.platform.is('ios') ? this.camera.DestinationType.FILE_URI : this.camera.DestinationType.DATA_URL,
- encodingType: this.camera.EncodingType.JPEG,
- mediaType: this.camera.MediaType.PICTURE
- }
- this.camera.getPicture(options).then((imageData) => {
- let base64Image = null;
- //get photo from the camera based on platform type
- if (this.platform.is('ios'))
- base64Image = normalizeURL(imageData);
- else
- base64Image = "data:image/jpeg;base64," + imageData;
- //add photo to the array of photos
- this.imgurl =base64Image;
- }, (error) => {
- console.debug("Unable to obtain picture: " + error, "app");
- console.log(error);
- });
- }
- openGallery() {
- let cameraOptions = {
- sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
- destinationType: this.camera.DestinationType.FILE_URI,
- quality: 100,
- targetWidth: 1000,
- targetHeight: 1000,
- encodingType: this.camera.EncodingType.JPEG,
- correctOrientation: true
- };
- this.camera.getPicture(cameraOptions).then((file_uri) => {
- //add photo to the array of photos
- this.imgurl=normalizeURL(file_uri);
- }, (error) => {
- console.debug("Unable to obtain picture: " + error, "app");
- console.log(error);
- });
- }
- /*proceed() {
- this.navCtrl.setRoot('TabsPage');
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement