html2canvas渲染高分辨率图像

时间:2018-03-13 06:23:45

标签: html html2canvas

我想使用html2canvas渲染4k高分辨率图像但不渲染。 请指教。

var element = $("#html-content-holder"); // global variable
var getCanvas; // global variable
 
    $("#btn-Preview-Image").on('click', function () {
         html2canvas(element, {
         onrendered: function (canvas) {
                $("#previewImage").append(canvas);
                getCanvas = canvas;
             }
         });
    });

	$("#btn-Convert-Html2Image").on('click', function () {
    var imgageData = getCanvas.toDataURL("image/png");
    // Now browser starts downloading it instead of just showing it
    var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
    $("#btn-Convert-Html2Image").attr("download", "your_pic_name.png").attr("href", newData);
	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://files.codepedia.info/files/uploads/iScripts/html2canvas.js"></script>
</head>
<body>
   
<div id="html-content-holder">
<img 
 width="400" height="auto"src="https://www.wallpaperup.com/uploads/wallpapers/2016/06/24/991808/9ab236cccae5470451c20329ca43ec6b-1000.jpg">
    
</div>
<input id="btn-Preview-Image" type="button" value="Preview"/>

<br/>
<h3>Preview :</h3>
<div id="previewImage">
</div>
预览不工作请告知。 谢谢

0 个答案:

没有答案