var reader = new FileReader();
reader.readAsArrayBuffer(file);//file 源文件
reader.onload = function(bf) {
var content = new DataView(this.result);
for (var i = 0; i < content.byteLength; i++) {
var br = content.getInt8(i) ^ coder;
content.setInt8(i, br);
}
var binary = '';
var bytes = new Uint8Array(content.buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
var str = window.btoa(binary);
//将图片转成base64字符串
var img = new Image();
img.src = 'data:image/png;base64,' + str;
}
转载请注明出处: http://sdxlp.cn/article/weixin3.1.html