zoukankan      html  css  js  c++  java
  • h5 图片生成

    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',
             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)
      },
    

      

    https://www.tongbiao.xyz/
  • 相关阅读:
    JavaBean和Map之间的转化
    java基础Map遍历
    sql server
    android之使用百度地图(1)
    Java基础知识2(字符串)
    Java基础知识1
    DAY12-Java中的类--接DAY10
    DAY11-LocalDate小练习
    DAY10-万物皆对象-2018-2-2
    DAY9-字符串笔记整理2018-1-19
  • 原文地址:https://www.cnblogs.com/tongbiao/p/10021688.html
Copyright © 2011-2022 走看看