备忘
多端生成图片:
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);
var scale = 6;
var canvas = document.createElement("canvas");
canvas.width = w * 2;
canvas.height = h * 2;
canvas.style.width = w + "px";
canvas.style.height = h + "px";
var context = canvas.getContext("2d");
context.scale(2, 2);
var opts = {
// allowTaint:true,
useCORS: true,
logging: false,
scale: scale,
dpi: window.devicePixelRatio * scale,
canvas: canvas,
width: w,
heigth: h
};
console.log(opts)
function dImg(canvas) {
document.querySelector(".down").setAttribute("href", canvas.toDataURL("image/png", 1.0));
$(".down")[0].click();
}
html2canvas.html2canvas(_canvas, opts).then(function (canvas) {
dImg(canvas)
});
clearInterval(timer)
}, 350)
},