base64编码里边没有逗号,可以这样:.substring(src.indexOf(",")+1)
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL("image/png");
return dataURL
// return dataURL.replace("data:image/png;base64,", "");
}
function main() {
var img = document.createElement('img');
img.src = './images/yeoman.png';
img.onload =function() {
var data = getBase64Image(img);
console.log(data);
}
document.body.appendChild(img);
}
main()