0
の代わりにImageURIの配列を返す私はプラグインイオンコルドバカメラからbase64で画像を取得しようとしていますが、それは私がフルパスを使用してみました以下の詳細イオンカメラのプラグインは、Android
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"
を配列で返します画像をベース64に変換する
$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;
};
しかし、それは私に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
});
}
注:FILE_URIではなくData_URLを使用すると、同じオブジェクトが返されます。