我试图加载一个名为“border.bmp”的图像,以便我可以将它用作WebGL的纹理。这是我参考图像的方式。loadImage()无法加载图像(P5.js WebGL)
var img;
function preload() {
img = loadImage("assets/border.bmp");
}
然后我在控制台中得到这个错误。
Access to Image at 'file:///C:/P5.js/empty-example/assets/border.bmp' from
origin 'null' has been blocked by CORS policy: Invalid response. Origin
'null' is therefore not allowed access.
什么是此错误消息?这是什么意思?我如何加载图像?
解决方案是使用简单的网络服务器。这将花费你不到2分钟。 [这是一个](https://greggman.github.io/servez/)和[这里有更多](https://stackoverflow.com/questions/12905426/what-is-a-faster-alternative-to-pythons -http - 服务器 - 或 - simplehttpserver)。服务你的p5.js文件夹,然后进入'http:// localhost:8080'或你决定使用的服务器的任何端口服务于 – gman