h5 图片生成
Posted tongbiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘, 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 图片生成的主要内容,如果未能解决你的问题,请参考以下文章