gpt4 book ai didi

javascript - 带有模式安全错误的 Internet Explorer 11 fillStyle

转载 作者:行者123 更新时间:2023-11-30 17:33:27 26 4
gpt4 key购买 nike

我得到的这个脚本可以在 Chrome、Safari 和 Firefox windwos/mac 中运行,但在 IE 11 中失败并出现安全错误。

http://jsfiddle.net/YkVgA/1/

知道如何在我用来自另一个域的纹理填充该 Canvas 后从该 Canvas 获取图像数据吗?

该图像启用了交叉原点。

<body><canvas id="mycanvas"></canvas>

var ctx = document.getElementById('mycanvas').getContext('2d');

var img = new Image();
img.crossOrigin = 'anonymous';
img.src = 'http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50';
img.onload = function () {
var ptrn = ctx.createPattern(img, 'repeat');
ctx.fillStyle = ptrn;
ctx.fillRect(0, 0, 150, 150);
var inData = ctx.getImageData(0, 0, 150, 150)
}

最佳答案

正如 fzzle 在评论中指出的那样,IE(目前)还不支持图像的跨源请求。

可能的解决方案

在这种客户端无法请求使用 CORS 的特殊情况下,选项有些受限,因此您必须:

  • 创建与页面同源的图像副本
  • 在服务器上使用代理页面请求图像,然后将其提供给同源的客户端

关于javascript - 带有模式安全错误的 Internet Explorer 11 fillStyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com