我正在开发一个Ionic应用程序,一个任务是通过相机或画廊选择配置文件,然后使用Ionic Native ImagePicker选择图片和裁剪,它可以选择并裁剪,但不会显示在html前页面中,我的代码如下:
openImagePickerCrop(){
this.imagePicker.hasReadPermission().then(
(result) => {
if(result == false){
// no callbacks required as this opens a popup which returns async
this.imagePicker.requestReadPermission();
}
else if(result == true){
this.imagePicker.getPictures({
maximumImagesCount: 3
}).then(
(results) => {
for (var i = 0; i < results.length; i++) {
this.crop.crop(results[i], {quality: 100}).then(
newImage => {
this.imgResponse.push('data:image/jpeg;base64,' + newImage);
console.log("Image selected - " + newImage);
},
error => console.error("Error cropping image", error)
);
}
}, (err) => console.log(err)
);
}
}, (err) => {
console.log(err);
});
}
这是我的html代码:
<ion-item class="input-item">
<ion-label position="floating">Photo</ion-label>
<div class='images' *ngFor="let img of imgResponse">
<img src="{{img}}" alt="" srcset="" />
</div>
<ion-card-content>
<ion-button color="medium" size="large" (click)="openImagePickerCrop()">
<ion-icon slot="icon-only" name="camera"></ion-icon>
</ion-button>
</ion-card-content>
</ion-item>
我在哪里做错了,请帮忙。