[英]html2canvas saving canvas images with extension
I have a web page with button onclick on that button a screenshot of this page should be taken and downloaded with (.jpg) extension. 我有一个带有onclick按钮的网页,应在该按钮上截取该页面的屏幕快照,并以(.jpg)扩展名下载。 to do that I use the following code:
为此,我使用以下代码:
$("#Finish").on('click', function () { // take a screenshot and save it. html2canvas(element, { onrendered: function (canvas) { $("#previewImage").append(canvas); getCanvas = canvas; DownloadImage(); } }); }); function DownloadImage() { var imageData = getCanvas.toDataURL("image/png"); var newData = imageData.replace(/^data:image\\/png/, "data:application/octet-stream"); window.open(newData); }
when i click the button: 当我单击按钮时:
As you see I have image with "download" Name without any extension. 如您所见,我的图像带有“下载”名称,没有任何扩展名。 I need to download the image with specific name and extension for example "myImage.jpg"
我需要下载具有特定名称和扩展名的图像,例如“ myImage.jpg”
If you can change the button into a <a>
tag, you should be able to use the download attribute. 如果可以将按钮更改为
<a>
标记,则应该能够使用download属性。
$('#image-link').attr('href', 'data:image/png;base64,<data>").attr('download', 'filename.png');
Haven't played around with it too much myself but it is said to work in Firefox, Chrome and Edge: https://caniuse.com/#feat=download 我自己并没有玩太多,但是据说它可以在Firefox,Chrome和Edge中使用: https : //caniuse.com/#feat=download
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.