我正在尝试在图像中获取画布,但是,我收到了异常“操作不安全”。
查看代码:
function CreateLookOnCanvas(ItensLook){
var myCanvas = document.getElementById("story-imagelook");
var context = myCanvas.getContext("2d");
var font;
var style;
var x, y, width, height;
var img;
ItensLook.forEach(function (entry) {
y = entry[1];
x = entry[2];
width = entry[3];
height = entry[4];
for (var i = 0; i < 5; i++) {
if (entry.length == 12) {
font = entry[9] + " " + entry[8] + " " + entry[7] + " " + entry[6] + " ";
style = entry[5];
context.font = font;
context.fillStyle = style;
context.fillText(entry[11], x, y, width, height);
}
else {
img = new Image();
img.src = entry[5];
context.drawImage(img, x, y, width, height);
}
}
});
console.log(myCanvas.toDataURL("image/png"));
}
我正在尝试在控制台上打印,但是,无论我在哪里使用myCanvas.toDataURL("image/png")
,我都会遇到此异常
更新
现在,我正在尝试使用img.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAiElEQVR42r2RsQrDMAxEBRdl8SDcX8lQPGg1GBI6lvz/h7QyRRXV0qUULwfvwZ1tenw5PxToRPWMC52eA9+WDnlh3HFQ/xBQl86NFYJqeGflkiogrOvVlIFhqURFVho3x1moGAa3deMs+LS30CAhBN5nNxeT5hbJ1zwmji2k+aF6NENIPf/hs54f0sZFUVAMigAAAABJRU5ErkJggg=="
和异常连续体。
SOLUCTION
在网上搜索了几个小时后(google),我找到了这个网页:http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#security-with-canvas-elements