html轉為圖片插件:html2canvas保存圖片模糊問題解決


  使用官網的CDN:

<script src="http://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>

  網上可以查到很多解決方案,常用的主要就是:canvas先放大,其次加個dpi效果也可以,代碼如下:

var canvas = document.createElement("canvas"); var context = canvas.getContext("2d"); var scale = 4; canvas.width = 70 * scale; canvas.height = 70 * scale; canvas.getContext("2d").scale(scale, scale); var opts = { dpi: window.devicePixelRatio * 4, scale: scale, // 添加的scale 參數
    canvas: canvas, //自定義 canvas // logging: true, //日志開關,便於查看html2canvas的內部執行流程
    width: 70, //dom 原始寬度
    height: 70, useCORS: true // 【重要】開啟跨域配置
}; html2canvas(document.querySelector("#capture"), opts).then(canvas => { document.body.appendChild(canvas); });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM