[removed] toDataUrl() throwing “Security Error: Tainted canvases may not be exported.”

后端 未结 3 850
暗喜
暗喜 2021-01-12 17:15

I have an HTML5 canvas on which I draw an image from an svg.

HTML

         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-12 17:31

    I solved this by converting the svg to a data URL instead of a Blob.

    I removed var url = DOMURL.createObjectURL(svg); and replaced img.src = url; with this:

    function buildSvgImageUrl(svg) {
        b64 = window.btoa(svg);
        return "data:image/svg+xml;base64," + b64;
    }
    
    img.src = buildSvgImageUrl(data);
    

    Now it works flawlessly.

提交回复
热议问题