zoukankan      html  css  js  c++  java
  • html2canvas,html2canvas截取图片,html2canvas快照,vue html2canvas快照,vue使用html2canvas截图

    页面截图,快照vue使用

    第一步

    npm install html2canvas

    第二步  

    在使用的页面引入

    import html2canvas from 'html2canvas';    

    页面 

    截图内容外框 id    nodeBox

    <template>
      <div class="app-container">
        <div id="nodeBox">
                <div class="body-box">
        内容内容
                  </div>
          </div>
     
        <img id="downImg" :src="dataurl" alt />
      </div>
    </template>        

    js

      //截取图片
        setImage() {
        //要先置顶,避免只截图一半
          window.pageYoffset = 0;
          document.documentElement.scrollTop = 0;
          document.body.scrollTop = 0;
          let that = this;
          var canvas2 = document.createElement("canvas");
          let _canvas = document.getElementById("nodeBox");
          var w = parseInt(window.getComputedStyle(_canvas).width);
          var h = parseInt(window.getComputedStyle(_canvas).height);
          //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
          canvas2.width = w ;
          canvas2.height = h ;
          canvas2.style.width = w + "px";
          canvas2.style.height = h + "px";
          //可以按照自己的需求,对context的参数修改,translate指的是偏移量
          var context = canvas2.getContext("2d");
          html2canvas(document.getElementById("nodeBox"), {
            canvas: canvas2
          }).then(function(canvas) {
            var pageData = canvas.toDataURL("image/jpeg", 1.0);
            that.dataurl = pageData;
          crudMatchingConfim.uploadImage64({ file: pageData }).then(data => {
              var configPic = data.fileName;
              crudMatchingConfim
                .fkBankExcelConfirm({
                  configPic: configPic,
                  batchNo: that.$route.query.batchNo
                })
                .then(data => {
                  that.nextDetails();
                });
            });

          });
        },

         // 下载图片
    // that.saveFile( // pageData.replace("image/jpeg", "image/octet-stream"), // new Date().getTime() + ".jpeg" // ); }); }, /** * 在本地进行文件保存 * @param {String} data 要保存到本地的图片数据 * @param {String} filename 文件名 */ saveFile(data, filename) { var save_link = document.createElementNS( "http://www.w3.org/1999/xhtml", "a" ); save_link.href = data; save_link.download = filename; var event = document.createEvent("MouseEvents"); event.initMouseEvent( "click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null ); save_link.dispatchEvent(event); }, getBlob(canvas) { //获取blob对象 var data = canvas.toDataURL("image/jpeg", 1); this.dataurl = data; console.log(this.dataurl); data = data.split(",")[1]; data = window.atob(data); var ia = new Uint8Array(data.length); for (var i = 0; i < data.length; i++) { ia[i] = data.charCodeAt(i); } return new Blob([ia], { type: "image/jpeg" }); }
  • 相关阅读:
    Android移动软件开发总结
    (译)综合指南:通过Ubuntu 16.04上从Source构建来安装支持GPU的Caffe2
    caffe2 环境的搭建以及detectron的配置
    SSD-Tensorflow 从工程角度进行配置
    简单实现Ubuntu16.04 + caffe2 + CUDA9.0 + cuDNN8.0
    Tensorflow1.5.0+cuda9.0+cudnn7.0+gtx1080+ubuntu16.04
    Cuda 9.2 CuDnn7.0 官方文档解读
    解决 Faster R-CNN 图片中框不在一张图片上显示的问题
    (转载)YOLO配置文件理解
    CycleGAN 配置及其实现
  • 原文地址:https://www.cnblogs.com/FACESCORE/p/13273392.html
Copyright © 2011-2022 走看看