【问题标题】:Get Image name and base64 format image path in cordova在cordova中获取图片名称和base64格式图片路径
【发布时间】:2016-08-24 00:32:17
【问题描述】:

当用户从照片库中选择图像时,我需要获取图像名称和 base64 图像。我正在使用 cordova 相机插件从图库中获取图像,但我没有同时获取图像名称和 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);
    });

我怎样才能通过单击将这两个调用结合起来?

【问题讨论】:

  • 我要给你看cordova代码吗?因为我不熟悉ionic

标签: cordova ionic-framework cordova-plugins ionic2


【解决方案1】:

Documentation 表示 Camera.DestinationType : 枚举,一次可以使用一个作为 FILE_URI 或 DATA_URL 或 NATIVE_URI

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 2012-01-04
    相关资源
    最近更新 更多