将受污染的画布下载为PNG

我试图创建一个按钮,当按下该按钮时,会将canvas元素下载为PNG文件。

function downloadImage(canvas)
{
    let url = canvas.toDataURL("image/png");
    window.open(url);
}

This code works for untainted canvases, but the canvas I'm trying to download an image of is already tainted so I cannot run .toDataURL() on it. Many threads I've seen dealing with tainted canvases are related to creating image displays of the canvas, but is there any way to directly download it without creating an intermediate image element?

我的网站非常简单,目前我不在任何服务器上运行它(只需在Google Chrome中打开index.html文件)。但是,我也不想更改任何本地浏览器设置,因为我希望它可以在多个不同的浏览器上运行。

评论