您好,登錄后才能下訂單哦!
<body>
<div class="card-bg">
</div>
</body>
$(function() {
var canvas2 = document.createElement("canvas");
let _canvas = document.querySelector('.card-bg');//需要替換成圖片的html區域
//獲取寬高
var w = parseInt(window.getComputedStyle(_canvas).width);
var h = parseInt(window.getComputedStyle(_canvas).height);
//將canvas畫布放大若干倍,然后盛放在較小的容器內,就顯得不模糊了
canvas2.width = w * 2;
canvas2.height = h * 2;
canvas2.style.width = w + "px";
canvas2.style.height = h + "px";
//可以按照自己的需求,對context的參數修改,translate指的是偏移量
// var context = canvas.getContext("2d");
// context.translate(0,0);
var context = canvas2.getContext("2d");
context.scale(1.85, 1.7);
html2canvas(_canvas,{canvas:canvas2}).then(function(canvas) {
var imgUri = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // 獲取生成的圖片的url
$(".card-bg").html('<img class="down" src="'+imgUri+'" >');
})
});
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。