I am using the following code to save the content of div (image and text) as an image using html2canvas.

$(function() {

$("#save").click(function() {

var flag = true;

var imgpath = document.getElementById('file').value;

if(imgpath.length == 0)

{

alert('Please select image file to upload.');

flag = false;

}

else

{

html2canvas($('.body740'), {

onrendered: function(canvas) {

theCanvas = canvas;

var url = canvas.toDataURL("image/png");

var br = document.createElement("br");

var center = document.createElement("center");

var newImg = document.createElement("img"); // create img tag

newImg.src = url;

$(".body740").hide();

$("#canvas").show(); //div where the final image is shown

document.getElementById("rsimg").src=url;

document.getElementById("rsa").href=url;

}

});

}

});

});

But, when I click the save image button, it takes a lot of time to generate the image. Why is it taking so much time to load? What is the issue?

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐