Loading

js 图片转base64

let canvas = document.createElement("canvas");
let img = document.getElementById('img');
canvas.width = img.width;
canvas.height = img.height;
let ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
let dataURL = canvas.toDataURL("image/png");
console.log(dataURL);  // 结果

 注: 不能使用本地图片,存在跨域问题

posted @ 2020-09-02 15:58  头牌彭鱼宴、  阅读(106)  评论(0编辑  收藏  举报