如何使用 pygame.image.load() 加载图像? [英] How to load image using pygame.image.load()?

查看:477
本文介绍了如何使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆