[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Problem loading TGA images from StringIO



I'm trying to have my game use a zipped file instead of loading from a 
data directory.  This should be possible by wrapping zip data in 
StringIO objects.  My image files are in TGA format and when I try to load 
them, I get the following error:

pygame.error: Unsupported image format

However, if I try to load BMP images from the zip file, it all works.  
Here's some sample code to demonstrate the problem (assuming you have 
test.tga in a test.zip file):

import sys, zipfile, StringIO, pygame

if __name__ == '__main__':
    pygame.init()
    surface = pygame.display.set_mode((640,480), 0)
    zf = zipfile.ZipFile('test.zip', 'r')
    data = zf.read('test.tga')
    img = pygame.image.load(StringIO.StringIO(data))
    surface.blit(img, (0,0))
    pygame.display.flip()

    do_quit = False
    while not do_quit:
        for event in pygame.event.get():
            if event.type in [pygame.QUIT, pygame.KEYDOWN]:
                do_quit = True

    pygame.quit()


----

Of course, I can convert all my images to BMP, but I was curious why this 
was happening.

Thanks,
Josh