如何使用 pygame.image 加载 PNG 文件? [英] How to load PNG files with pygame.image?

查看:87
本文介绍了如何使用 pygame.image 加载 PNG 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想用那段代码用 pygame 加载图像:

导入pygamemyimage = pygame.image.load("bla.png")

我得到了错误:

<块引用>

pygame.error: 文件不是 Windows BMP 文件

请注意,当我调用 pygame.image.get_extended() 时,它返回 0.我怎样才能解决这个问题并获得其他格式?

谢谢

解决方案

Pygame 文档图片明确表示

<块引用><块引用>

图像模块是 Pygame 的必需依赖项,但它仅可选地支持任何扩展文件格式.默认情况下,它只能加载未压缩的 BMP 图像.

所以,我想你应该跑

pygame.image.get_extended() # 返回一个布尔值

检查您是否可以加载其他扩展程序的图像.如果没有,我想您将需要安装 Python 映像库才能获得 Pygame 支持的扩展文件格式.

或者,您可以随时将图像转换为 BMP 以避免麻烦.

I'm simply trying to load an image with pygame with that piece of code :

import pygame
myimage = pygame.image.load("bla.png")

And I get the error :

pygame.error: File is not a Windows BMP file

Note that when I call pygame.image.get_extended() it returns 0. How can I fix that and get the other formats ?

Thanks

解决方案

The Pygame documentation for images explicitly says

The image module is a required dependency of Pygame, but it only optionally supports any extended file formats. By default it can only load uncompressed BMP images.

So, I suppose you should run

pygame.image.get_extended() # returns a bool

to check if you can load images of other extensions. If not, I suppose you will need Python imaging libraries to be installed to get extended file formats to be supported by Pygame.

OR, you could always convert the images to BMP to avoid the hassle.

这篇关于如何使用 pygame.image 加载 PNG 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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