2

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

kaldo
  • 257
  • 2
  • 3
  • 8
  • in your example you are loading a gif?? but you want a png? – John Riselvato Nov 09 '13 at 20:13
  • 5
    Well, he wanted to load a .PNG file, tried to load a .GIF file, and the Pygame system complained that it is not a .BMP file. I wonder where the .JPG file is, because that's probably the only thing that is missing here. – Lasse V. Karlsen Nov 09 '13 at 20:14
  • Oops, my bad. I actually tried to load 'bla.png' and the file in my directory is a png. Just corrected the example. The problem remains. – kaldo Nov 09 '13 at 20:38
  • What platform are you on? What version of pygame are you using? – kevintodisco Nov 09 '13 at 21:33
  • I'm on Ubuntu 13.04 and I develop with python 3.3, I just installed pygame 1.9.2 following those instructions : http://python-forum.org/viewtopic.php?f=25&t=2716 – kaldo Nov 09 '13 at 22:07
  • You can always use PIL to convert images to bmp files. – User Nov 09 '13 at 22:48

1 Answers1

3

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.

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
  • I've been trying to install imaging libraries, such as libpng or libjpeg, the error has changed. It's now : "Couldn't open 'bla.png'" – kaldo Nov 10 '13 at 12:51
  • myimage = pygame.image.load("bla.png") pygame.error: File is not a Windows BMP file. By the way `pygame.image.get_extended()` still returns 0. – kaldo Nov 10 '13 at 13:00
  • 1
    I suppose, you need some other imaging library, mostly PIL should do the job. Check out http://www.pythonware.com/products/pil/ & https://pypi.python.org/pypi/PIL‎ – shad0w_wa1k3r Nov 10 '13 at 13:10