JavaScript实现图片URL转DataURL

@fright  November 10, 2017
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);


评论已关闭