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

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



On 1/19/07, Kamilche <kamilche@xxxxxxxxxxxx> wrote:
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.)

That doesn't seem to make any sense... you've already loaded the picture, why convert it to a string just to convert it back to a picture? It's using up about the same amount of RAM as a string or as an image object.

-bob