码迷,mamicode.com
首页 > 其他好文 > 详细

h5 图片生成

时间:2018-11-26 19:56:35      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:cal   create   load   device   res   img   下载   nload   test   

createImg(store, data) {
    let timer = setTimeout(function (params) {
      let _canvas = document.querySelector(".setPictureSection");
      var w = parseInt(window.getComputedStyle(_canvas).width);
      var h = parseInt(window.getComputedStyle(_canvas).height);
      //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
      var canvas2 = document.createElement("canvas");
      var scale = 2;

      canvas2.width = w * 2;
      canvas2.height = h * 2;
      canvas2.style.width = w + "px";
      canvas2.style.height = h + "px";
      canvas2.getContext("2d").scale(scale, scale);

      html2canvas(document.querySelector(".setPictureSection"), {
        // allowTaint: true,
        // taintTest: false,
        scale: 1,
        dpi: window.devicePixelRatio * 5,
        // canvas: canvas2,
        userCORS: true,
        backgroundColor: ‘#ffffff‘,
        width: w,
        height: h,
        x: 0,
        y: 0,
      }).then(function (canvas) {
        //document.body.appendChild(canvas);
        //canvas转换成url,然后利用a标签的download属性,直接下载,绕过上传服务器再下载
        document.querySelector(".down")
          .setAttribute("href", canvas.toDataURL("image/png", 1.0));
        $(".down")[0].click();

      });
      timer = null;
    }, 350)
  },

  

h5 图片生成

标签:cal   create   load   device   res   img   下载   nload   test   

原文地址:https://www.cnblogs.com/tongbiao/p/10021688.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!