我试图将图像编码为base64并将其发送到服务器。当我检索到的图像全部显示为空白。Phonegap编码图像base64
我使用的编码它的代码是这样的:
encodeImageUri = function(imageUri) {
var c = document.createElement('canvas');
var ctx = c.getContext("2d");
var img = new Image();
img.onload = function() {
c.width = this.width;
c.height = this.height;
ctx.drawImage(img, 0, 0);
};
img.src = imageUri;
var dataURL = c.toDataURL("image/jpeg");
return dataURL.slice(22, dataURL.length);
}
来自Using PhoneGap, How to get base64 image data of the photo chosen from photo library in iPhone
它仍然不起作用,我得到了一串A的字符串 –
@ danielrvt-sgb:图像是否与您的页面在同一个域上?你确定这个字符串是错的吗? –
图像与手机相机拍摄并存储在SD卡中。我测试了这个页面中的字符串:http://www.freeformatter.com/base64-encoder.html并返回一个空白图像 –