Created
July 29, 2020 09:57
-
-
Save vaibhavgehani/b1bd214cf4cb4c9c1254c965deb15259 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //home.page.ts | |
| import { Component } from '@angular/core'; | |
| import { Camera, CameraOptions } from '@ionic-native/Camera/ngx'; | |
| import { File } from '@ionic-native/file/ngx'; | |
| import { ActionSheetController } from '@ionic/angular'; | |
| @Component({ | |
| selector: 'app-home', | |
| templateUrl: 'home.page.html', | |
| styleUrls: ['home.page.scss'], | |
| }) | |
| export class HomePage { | |
| croppedImagepath = ""; | |
| isLoading = false; | |
| imagePickerOptions = { | |
| maximumImagesCount: 1, | |
| quality: 50 | |
| }; | |
| constructor( | |
| private camera: Camera, | |
| public actionSheetController: ActionSheetController, | |
| private file: File | |
| ) { } | |
| pickImage(sourceType) { | |
| const options: CameraOptions = { | |
| quality: 100, | |
| sourceType: sourceType, | |
| destinationType: this.camera.DestinationType.FILE_URI, | |
| encodingType: this.camera.EncodingType.JPEG, | |
| mediaType: this.camera.MediaType.PICTURE | |
| } | |
| this.camera.getPicture(options).then((imageData) => { | |
| // imageData is either a base64 encoded string or a file URI | |
| // If it's base64 (DATA_URL): | |
| // let base64Image = 'data:image/jpeg;base64,' + imageData; | |
| }, (err) => { | |
| // Handle error | |
| }); | |
| } | |
| async selectImage() { | |
| const actionSheet = await this.actionSheetController.create({ | |
| header: "Select Image source", | |
| buttons: [{ | |
| text: 'Load from Library', | |
| handler: () => { | |
| this.pickImage(this.camera.PictureSourceType.PHOTOLIBRARY); | |
| } | |
| }, | |
| { | |
| text: 'Use Camera', | |
| handler: () => { | |
| this.pickImage(this.camera.PictureSourceType.CAMERA); | |
| } | |
| }, | |
| { | |
| text: 'Cancel', | |
| role: 'cancel' | |
| } | |
| ] | |
| }); | |
| await actionSheet.present(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment