gpt4 book ai didi

javascript - 将表格转换为 Canvas ,然后使用 jQuery 将 Canvas 下载为图像

转载 作者:行者123 更新时间:2023-12-01 02:30:44 26 4
gpt4 key购买 nike

我正在使用 HTML2Canvas 将表格转换为 Canvas ,然后尝试使用下载按钮下载图像。我的代码如下:

$("input[alt='save-image']").click(function() {
html2canvas($("table"), {
onrendered: function(canvas) {
this.href = canvas.toDataURL();
this.download = "mypainting.png";
}
});
});

表格转换为图像;但是,该图像永远不会下载。如果我做错了什么或者您想了解更多信息,请告诉我。

最佳答案

您可以像这样下载图像 -

                html2canvas($('table').get(0)).then( function (canvas) {
// document.body.appendChild(canvas);//
var a = document.createElement('a');
// toDataURL defaults to png, so we need to request a jpeg, then convert for file download.
//a.href = canvas.toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream");
a.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
a.download = 'mypainting.png';
a.click();
});

关于javascript - 将表格转换为 Canvas ,然后使用 jQuery 将 Canvas 下载为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48333125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com