标签:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" /> <script> function init() { var canvas = document.createElement(‘canvas‘) var ctx = canvas.getContext(‘2d‘); var img = new Image(); img.src = "临时图片/1.png"; img.onload = function() { //原图的大小 ctx.drawImage(img, 0, 0, 100, 100); console.log(canvas.toDataURL()) document.getElementById(‘imgbase64‘).src = canvas.toDataURL(); } } </script> </head> <body onload="init()"> <img id="imgbase64" src="" /> </body> </html>
标签:
原文地址:http://www.cnblogs.com/zhaojia-dream/p/5570761.html