我試圖將圖像編碼爲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並返回一個空白圖像 –