简体   繁体   English

加载目录p5.js的所有图像

[英]Load all images of directory p5.js

I'm new into p5.js and achieved to play around with loading images. 我是p5.js的新手,可以加载图像。 Now I want to load a bunch of images which are in the same folder. 现在,我想加载一堆位于同一文件夹中的图像。 Is it possible to load these in a loop or somehow I don't have to know their names? 是否可以循环加载这些文件,或者我不必知道它们的名称?

Thank you very much for your suggestions. 非常感谢您的建议。 Yingrjimsch Yingrjimsch

First I think you need to be a little more specific about where the images are: 首先,我认为您需要更加详细地说明图像的位置:

  • Are they on the user's hard drive? 它们在用户的硬盘上吗?
  • Are they on the web somewhere? 他们在网上某个地方吗?

Depending on the answer to those questions, you can then google for a more specific solution. 根据这些问题的答案,然后您可以在Google上搜索更具体的解决方案。 Googling "JavaScript load directory of images" will return a ton of results. 谷歌搜索“ JavaScript加载图像目录”将返回大量结果。

If you're talking about loading a directory of images from the web, which approach you take might also depend on the behavior of your web server that's hosting the files. 如果您要谈论从Web加载图像目录,则采用哪种方法还可能取决于承载文件的Web服务器的行为。 For example some file servers will automatically create an index.html file inside every directory that just lists the other files in that directory. 例如,某些文件服务器将在每个目录内自动创建一个index.html文件,该目录仅列出该目录中的其他文件。 If that's the case, then you can just parse that link to get the URLs of the images in the directory. 如果是这种情况,那么您只需解析该链接即可获取目录中图像的URL。 If not, you might have to create that file yourself. 如果没有,您可能必须自己创建该文件。

There are probably other approaches, but that's how I'd do it. 可能还有其他方法,但这就是我要做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM