网上找了很多方法,要么说JS不能转,要么就是转换不了,以下是找到的完美的解决方法,
function
convertImgToBase64(url, callback, outputFormat){
var
canvas = document.createElement(
'CANVAS'
),
ctx = canvas.getContext(
'2d'
),
img =
new
Image;
img.crossOrigin =
'Anonymous'
;
img.onload =
function
(){
canvas.height = img.height;
canvas.width = img.width;
ctx.drawImage(img,0,0);
var
dataURL = canvas.toDataURL(outputFormat ||
'image/png'
);
callback.call(
this
, dataURL);
canvas =
null
;
};
img.src = url;
}
// Base64DataURL
alert(basearr[1]);
});
!评论内容需包含中文
是不是crossOrigin兼容性问题?还是微信本身做了限制