Tainted canvases may not be exported

后端 未结 10 1577
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 05:21

I want to save my canvas to a img. I have this function:

function save() {
    document.getElementById(\"canvasimg\").style.border = \"2px solid\";
    var d         


        
10条回答
  •  长发绾君心
    2020-11-22 06:13

    If you're using ctx.drawImage() function, you can do the following:

    var img = loadImage('../yourimage.png', callback);
    
    function loadImage(src, callback) {
        var img = new Image();
    
        img.onload = callback;
        img.setAttribute('crossorigin', 'anonymous'); // works for me
    
        img.src = src;
    
        return img;
    }
    

    And in your callback you can now use ctx.drawImage and export it using toDataURL

提交回复
热议问题