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

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

问题描述

我只是想用这段代码加载带有pygame的图像:

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

我收到错误:


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


请注意,当我调用 pygame.image.get_extended()时,它返回0.
如何修复它并获取其他格式?



谢谢

解决方案

图像的Pygame文档明确说明


< blockquote>

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



所以,我想你应该运行

  pygame.image.get_extended()#返回bool 

检查是否可以加载其他扩展程序的图像。如果没有,我想你需要安装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天全站免登陆