I am simply trying to allow a user to take a photo, store it as a data URI and then display that image. For some reason this only displays a boken image link and I'm not sure I understand. selectImage()
should allow the user to either select an image or take a new one, then display the image.
My view:
<ion-row *ngIf="imageSrc">
<ion-col class="ion-text-center">
<img alt="cropped photo" height="500px" [src]="imageSrc" />
<p>{{imageSrc}}</p>
</ion-col>
</ion-row>
Component:
selectImage() : void {
this.photo.selectImageSheet().then(() => {
if ( typeof(this.photo.imageSource) == 'number' ) {
this.photo.pickImage(this.photo.imageSource).then(imageURI => {
this.global.handleResponse(imageURI)
this.imageSrc = imageURI
})
}
})
}
Photo service:
pickImage(sourceType: number) : Promise<any> {
return new Promise((resolve, reject) => {
this.selectImage(sourceType).then( imageURI => {
resolve(imageURI)
})
})
}
selectImage(srcType : number = 1) : Promise<any> {
let options: CameraOptions = {
quality: 100,
sourceType: srcType,
targetWidth: 600,
targetHeight: 1200,
destinationType: this.camera.DestinationType.FILE_URI,
correctOrientation: true,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
return new Promise(resolve => {
this.camera.getPicture(options)
.then((imageURI) => {
this.imageData = imageURI;
resolve(this.imageData)
})
.catch(err => this.globals.handleResponse(JSON.stringify(err)))
})
}
The documentation seems pretty clear that the FILE_URI
should be able to be set as the src
so I'm really not sure what could be going wrong...
navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); function onSuccess(imageURI) { var image = document.getElementById('myImage'); image.src = imageURI; } function onFail(message) { alert('Failed because: ' + message); }