SurfaceLoadanimagefromafilesou" />

pygame.image

您所在的位置:网站首页 制造业pmi指数说明了什么 pygame.image

pygame.image

2022-12-23 10:12| 来源: 网络整理| 查看: 265

load new image from a file (or file-like object) load(filename) -> Surface load(fileobj, namehint="") -> Surface

Load an image from a file source. You can pass either a filename, a Python file-like object, or a pathlib.Path.

Pygame will automatically determine the image type (e.g., GIF or bitmap) and create a new Surface object from the data. In some cases it will need to know the file extension (e.g., GIF images should end in ".gif"). If you pass a raw file-like object, you may also want to pass the original filename as the namehint argument.

The returned Surface will contain the same color format, colorkey and alpha transparency as the file it came from. You will often want to call pygame.Surface.convert()change the pixel format of an image with no arguments, to create a copy that will draw more quickly on the screen.

For alpha transparency, like in .png images, use the pygame.Surface.convert_alpha()change the pixel format of an image including per pixel alphas method after loading so that the image has per pixel transparency.

Pygame may not always be built to support all image formats. At minimum it will support uncompressed BMP. If pygame.image.get_extended()test if extended image formats can be loaded returns True, you should be able to load most images (including PNG, JPG and GIF).

You should use os.path.join() for compatibility.

eg. asurf = pygame.image.load(os.path.join('data', 'bla.png'))


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3