Я работаю с ionic 3 Framework. И я не знаю, как преобразовать изображение base64 в blob. Спасибо.
.ts файл
openCamera() {
let actionSheet = this.actionSheetCtrl.create({
title: 'Edit Your Profile Picture',
buttons: [
{
text:'Camera',
icon: 'ios-camera',
role: 'destructive',
handler: () => {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
saveToPhotoAlbum: true,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
this.image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
alert(err)
});
}
},
{
text: 'Gallery',
icon: 'ios-images',
handler: () => {
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
sourceType:this.camera.PictureSourceType.PHOTOLIBRARY,
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
this.image = 'data:image/jpeg;base64,' + imageData;
//this.image = base64Image;
// alert(base64Image);
}, (err) => {
// Handle error
console.log(err);
});
}
},
{
text: 'Cancel',
role: 'cancel',
handler: () => {
}
}
]
});
actionSheet.present();
}
.html файл
<img (click)="openCamera()" [src]="domSanitizer.bypassSecurityTrustUrl(image)" class="before-img" >