【发布时间】:2016-01-25 08:02:45
【问题描述】:
我已经按照这个提琴手示例图像到 Base64。当我使用直接图像路径链接时它工作正常,但当我传递相机图像时它失败了。
Camera.getPicture().then(function(imageURI) {
var imageUrl = "http://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png";
convertImgToDataURLviaCanvas(imageUrl, function(base64Img) {
alert(base64Img);
});
var result = convertImgToDataURLviaCanvas(imageURI);
}, function(err) {
alert(err);
}, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
pictureSource: navigator.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: navigator.camera.DestinationType.FILE_URI,
saveToPhotoAlbum: true
});
function convertImgToDataURLviaCanvas(url, callback, outputFormat) {
var img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = function() {
var canvas = document.createElement('CANVAS');
var ctx = canvas.getContext('2d');
var dataURL;
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL(outputFormat);
alert(dataURL + "GANESH" + outputFormat);
callback(dataURL);
alert('5');
canvas = null;
};
img.src = url;
}
在这里,如果我给图像的直接路径它的工作,但当我使用相机图像时它不工作。帮帮我..提前谢谢。
【问题讨论】:
标签: javascript cordova camera ionic-framework base64