Ionic Camera Plugin returns 数组而不是 Android 上的 ImageURI

Ionic Camera Plugin returns an array instead of ImageURI on Android

我正在尝试从 Ionic Cordova 相机插件获取 base64 图像,但它 returns 我是一个包含以下详细信息的数组

MediaFile 
    end: 0
    fullPath: "file:/storage/emulated/0/Pictures/1471377463771.jpg"
    lastModified: null
    lastModifiedDate: 1471377464000
    localURL: "cdvfile://localhost/sdcard/Pictures/1471377463771.jpg"
    name: "1471377463771.jpg"
    size: 3188654
    start: 0
    type: "image/jpeg"

我尝试使用 fullPath 将图像转换为 base64

$scope.convertImgToBase64URL = function(url, callback, outputFormat){
    var img = new Image();
    img.crossOrigin = 'Anonymous';
    img.onload = function () {
        var canvas = document.createElement('CANVAS'),
        ctx = canvas.getContext('2d'), dataURL;
        canvas.height = this.height;
        canvas.width = this.width;
        ctx.drawImage(this, 0, 0);
        dataURL = canvas.toDataURL(outputFormat);
        callback(dataURL);
        canvas = null;
    };
    img.src = url;
};

但是那个returns我null。下面是我对相机插件的主要调用。

$scope.takePhoto = function () {
    var options = {
        destinationType: Camera.DestinationType.FILE_URI,
        sourceType: Camera.PictureSourceType.CAMERA,
    };

    $cordovaCapture.captureImage(options).then(function (imageURI) {
        $scope.convertImgToBase64URL(imageURI[0].fullPath, function (base64Img) {
            $scope.dataImg = "data:image/jpeg;base64," + base64Img;
            $scope.modal.show();
        })
    }, function (err) {
        // An error occurred. Show a message to the user
    });
}

注意:如果我使用 Data_URL 而不是 FILE_URI,它仍然 returns 我是同一个对象。

我认为您有关于 capture plugin and the camera plugin 的混合文档。 capture plugin 获取一个指定要拍摄多少张图像的对象

var options = { limit: 3 };

看起来你正在传递对应于 camera plugin 的参数。

我认为如果只是为了拍照,您最好使用 camera plugin 而不是那个捕捉器。您的代码最终会像这样:

var options = {
    quality: 75,
    destinationType: Camera.DestinationType.DATA_URL,
    sourceType: Camera.PictureSourceType.CAMERA,
    allowEdit: false,
    encodingType: Camera.EncodingType.JPEG,
    targetWidth: 720,
    targetHeight: 1280,
    popoverOptions: CameraPopoverOptions,
    saveToPhotoAlbum: false,
    correctOrientation: true
};

cordovaCamera.getPicture(options).then(function (imageData) {
    var base64Image = "data:image/jpeg;base64," + imageData;
});