如何使用 pygame.image.load() 加载图像? [英] How to load image using pygame.image.load()?
问题描述
我只想知道语法.如何使用 pygame.image.load() 加载图像?让我们举个例子,我想加载一个名为 cat.png 的图像 - 并输入这个
I just want to know the syntax. How do I load an image using pygame.image.load() ? Let's take an example, I want to load an image called cat.png - and type this
pygame.image.load('cat.png')
那么,cat.png图片应该保存在哪里呢?
Then, where should the image cat.png be saved?
推荐答案
默认情况下,Python 仅在您当前的目录中搜索文件,但是,如果您希望从单独的目录加载图像,您可能会发现这很有用:从目录导入图像 (Python)
By default, Python only searches in your current directory for files, however, if you wish to load images from a separate directory, you may find this useful: Importing images from a directory (Python)
对于语法,我建议您参考文档,在这里:https://www.pygame.org/docs/ref/image.html#pygame.image.load
For the syntax, I reccomend you refer to the documentation, here: https://www.pygame.org/docs/ref/image.html#pygame.image.load
pygame.image.load()¶
load new image from a file
load(filename) -> Surface
load(fileobj, namehint="") -> Surface
Load an image from a file source. You can pass either a filename or a Python file-like object.
这篇关于如何使用 pygame.image.load() 加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!