我正在使用ionic3本机裁剪图像插件,它工作并具有src图像路径,但我需要将其更改为base64字符串以将其发送到服务器。如何更改它,这是我的裁剪图像代码,非常感谢。
console.log('buttonCamera clicked');
let cameraOptions = {
sourceType: this.camera.PictureSourceType.CAMERA,
destinationType: this.camera.DestinationType.FILE_URI,
quality: 100,
targetWidth: 500,
targetHeight: 500,
encodingType: this.camera.EncodingType.JPEG,
correctOrientation: true
}
this.camera.getPicture(cameraOptions)
.then(file_uri => {
this.crop.crop(file_uri, {quality: 100})
.then(
newImage => {console.log('new image path is: ' + newImage);
this.imageSrc = newImage},
error => console.error('Error cropping image', error)
);
},
err => console.log(err));
答案 0 :(得分:0)
只需在cameraOption上进行少量更改即可:
sudo apt install apache2 libapache2-mod-php7.2
sudo a2dismod php7.0
sudo a2enmod php7.2
sudo service apache2 restart
就完成了!
答案 1 :(得分:0)
在 Ionic 4 中,使用 file 本机插件调用 readAsDataURL
showCroppedImage(ImagePath){
this.isLoading = true;
var copyPath = ImagePath;
var splitPath = copyPath.split('/');
var imageName = splitPath[splitPath.length-1];
var filePath = ImagePath.split(imageName)[0];
this.file.readAsDataURL(filePath,imageName).then(base64=>{
this.croppedImagepath = base64;
this.isLoading = false;
},error=>{
alert('Error in showing image' + error);
this.isLoading = false;
});
}
查看完整的教程here