gpt4 book ai didi

javascript - Google Chrome 污染了本地镜像的 Canvas

转载 作者:行者123 更新时间:2023-11-27 22:32:16 24 4
gpt4 key购买 nike

我正在尝试使用 html 5 canvas 元素制作一个普通的 JavaScript 游戏,为了制作基于颜色的命中框,我需要从 Canvas 上的某些位置获取图像数据。每当我使用 getImageData() 时,我都会收到此错误:

Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.

Canvas 上显示的所有图像都是从本地文件中提取的。有什么办法可以让它在 Chrome 上运行吗?

我通过在页面上放置 html 图像标签并使用 context.drawImage(*img id, x, y*); 来绘制图像

最佳答案

启动本地服务器可能是更好的方法。 Chrome 仍然安全。

cd path/to/files
python -m SimpleHTTPServer

将浏览器指向

http://localhost:8000

original answer通过@gman

关于javascript - Google Chrome 污染了本地镜像的 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39459107/

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