<!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 > <img id="imgbase64" src="" /> </body> </html>
时间: 2024-10-12 23:58:38