首页 > Web开发 > 详细

使用html2canvas实现屏幕截图

时间:2019-09-11 15:42:52      阅读:275      评论:0      收藏:0      [点我收藏+]
      // 调用html2canvas插件
        html2canvas(document.body).then(function (canvas) {
          // canvas宽度
          var canvasWidth = canvas.width;
          // canvas高度
          var canvasHeight = canvas.height;
          // 调用Canvas2Image插件
          var img = Canvas2Image.convertToImage(canvas, canvasWidth, canvasHeight);
          //图片类型.宽度.高度.文件名
          let type = document.getElementById('sel') ? document.getElementById('sel').getAttribute('value') : null
          let w = document.getElementById('imgW') ? document.getElementById('imgW').getAttribute('value') : null
          let h = document.getElementById('imgH') ? document.getElementById('imgH').getAttribute('value') : null
          let f = document.getElementById('imgFileName') ? document.getElementById('imgFileName').getAttribute('value') : null
          w = (w === '') ? canvasWidth : w; //判断输入宽高是否为空,为空时保持原来的值
          h = (h === '') ? canvasHeight : h;
          // 调用Canvas2Image插件
          Canvas2Image.saveAsImage(canvas, w, h, type, f);
        });

使用html2canvas实现屏幕截图

原文:https://www.cnblogs.com/wwj007/p/11506575.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!