越简单越好!

JavaScript实现图片URL转DataURL

发表于 2017-06-30 16:40 | 177次阅读 0次点赞   JavaScript
var img = $('#img').get(0);
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL("image/png");
console.log(dataURL);
返回顶部 ^