当用户从照片库中选择图像时,我需要获取图像名称和base64图像 . 我使用cordova Camera插件从图库中获取图像,但我没有同时获取图像名称和base64图像 .
// to get base64 image
Camera.getPicture({
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
targetWidth: 1000,
targetHeight: 1000
}).then((imageData) => {
// imageData is a base64 encoded string
this.base64Image = "data:image/jpeg;base64," + imageData;
alert("this.base64Image="+this.base64Image);
}, (err) => {
console.log(err);
});
//to get image URL
Camera.getPicture({
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
targetWidth: 1000,
targetHeight: 1000
}).then((imagePath) => {
// imageData is a base64 encoded string
this.imagePath = imagePath;
alert("this.imagePath="+this.imagePath);
}, (err) => {
console.log(err);
});
如何通过单击结合这两个呼叫?
1 回答
但如果你想要base64和文件路径,你可以convert image to base64 in angularjs