将HTML画布捕获为gif/jpg/png/pdf?是否有可能捕获或打印在html画布中显示的图像或pdf?我希望通过画布生成一个图像,并能够从该图像生成一个PNG。
4 回答
肥皂起泡泡
TA贡献1829条经验 获得超6个赞
var canvas = document.getElementById("mycanvas");var img = canvas.toDataURL("image/png");
document.write('<img src="'+img+'"/>');
开心每一天1111
TA贡献1836条经验 获得超13个赞
<canvas id=canvas width=200 height=200></canvas> <script> window.onload = function() { var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); context.fillStyle = "green"; context.fillRect(50, 50, 100, 100); // no argument defaults to image/png; image/jpeg, etc also work on some // implementations -- image/png is the only one that must be supported per spec. window.location = canvas.toDataURL("image/png"); } </script>
幕布斯6054654
TA贡献1876条经验 获得超7个赞
var canvas = document.getElementById("mycanvas");var image = canvas.toDataURL("image/png");
document.write('<img src="'+image+'"/>');
var imageMimes = ['image/png', 'image/bmp', 'image/gif', 'image/jpeg', 'image/tiff']; //Extend as necessary var acceptedMimes = new Array(); for(i = 0; i < imageMimes.length; i++) { if(canvas.toDataURL(imageMimes[i]).search(imageMimes[i])>=0) { acceptedMimes[acceptedMimes.length] = imageMimes[i]; }}
var canvas = document.getElementById("mycanvas");var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); //Convert image to 'octet-stream' (Just a download, really)window.location.href = image;
添加回答
举报
0/150
提交
取消