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

[pygame] Load Graphics 30x faster than pygame.image.load



I discovered a technique for loading graphics quickly using Pygame, about 30x faster than a straight pygame.image.load.

The gist of it is convert the picture to a string with

   s = pygame.image.tostring(pic, 'RGBA')
   w, h = pic.get_size()

and later, when loading, use
   pygame.image.frombuffer(s, [w, h], 'RGBA')

Unfortunately, I can't use it in my current project, because I need to access the color palette of 256 color images. I can't use this technique to store and load these palettized images, because images come out solid black.

Hope this technique comes in useful to someone else tho! (Someone that doesn't need 256 color images.)

--Kamilche