图像无法在IE中的Canvas中加载

时间:2018-02-27 12:05:11

标签: angular typescript canvas base64

无法在画布中加载图像以获取编码Base64代码

代码

var html = new XMLSerializer().serializeToString(document.getElementById("d3"));
var img = document.getElementById("img") as HTMLImageElement
img.src = "data:image/svg+xml;base64," + btoa(html.toString())

var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;

var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);

var dataURL = canvas.toDataURL("image/png"); --> showing SecurityError

var data =  dataURL.replace("data:image/svg+xml;base64", "");

提前致谢

0 个答案:

没有答案