I try to display a photo took with my camera.
This is my HTML :
<ion-grid>
<ion-row>
<ion-col col-6>
<button ion-button full (click)="prendreUnePhoto()">Prendre une photo</button>
</ion-col>
<ion-col col-6>
<button ion-button full (click)="choisirUneImage()">Choisir une image</button>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-12>
<button ion-button full (click)="envoiMail()">Envoyer Email</button>
</ion-col>
</ion-row>
<ion-card>
<ion-card-header>Image</ion-card-header>
<ion-card-content>
<img [src]="currentImage" *ngIf="currentImage"/>
</ion-card-content>
</ion-card>
And then, this is my TypeScript :
currentImage = null
constructor(public navCtrl: NavController, public navParams: NavParams, private emailComposer : EmailComposer, private camera: Camera) {
}
prendreUnePhoto() {
const options: CameraOptions = {
sourceType: this.camera.PictureSourceType.CAMERA,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
this.currentImage = imageData;
}, (err) => {
// Handle error
console.log('Image error: ', err);
});
}
envoiMail(){
let email = {
to : 'bastien.roussel.19@gmail.com',
subject : '[IONIC] test mail',
body : 'Premier <b>email</b> de test depuis ionic 3',
attachments: [
this.currentImage
],
isHtml : true
};
this.emailComposer.open(email);
}
So, I want to display my photo on my card. What is the problem ? I followed many different tutorials, I read the Ionic doc, but I didn't find the solution.
I have to say you that : when I click on the button "Envoyer Email" (send email), my photo is correctly displayed on my mail with this code. But my image is not displayed on my mail if I use :
this.currentImage = 'data:image/jpeg;base64,' + imageData;
Thank you for your help.