首页 文章

获取cordova中的图像名称和base64格式图像路径

提问于
浏览
1

当用户从照片库中选择图像时,我需要获取图像名称和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 回答

  • 1

    文档说Camera.DestinationType:enum,可以一次使用一个作为FILE_URI或DATA_URL或NATIVE_URI

    但如果你想要base64和文件路径,你可以convert image to base64 in angularjs

相关问题