首页 > 解决方案 > 如何在使用 ionic 5 拍照或从库中选择照片后操作图像(裁剪和调整大小)

问题描述

基本上,我需要先操作我选择的图片,然后再将其放在 HTML 页面中。到目前为止我所做的是有两个选项加载图像或选择图像的操作表:

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'
}
]
});
}

这是pickImage函数

pickImage(sourceType) {
const options: CameraOptions = {
quality: 100,
sourceType,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
};
this.camera.getPicture(options)
.then((imageData) => {
this.crop.crop(imageData, {quality: 100 });
this.serviceps.logo = 'data:image/jpeg;base64,' + imageData;
}, error => console.error('Error cropping image', error));

}

那么现在如何在选择后立即添加裁剪和编辑图像?从昨天开始我一直在努力,但我做不到。

标签: javascripthtmlangularionic-framework

解决方案


推荐阅读