tags:

views:

143

answers:

1

I'm trying to load a transparent image into pygame using the following code:

def load_image(name, colorkey=None):
    fullname = os.path.join('data', name)
    try:
        image = pygame.image.load(fullname)
    except pygame.error, message:
        print 'Cannot load image:', fullname
        raise SystemExit, message
    image = image.convert()
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

For some reason, everytime I load the image the background is automatically changed to black? I'm not using the colorkey in this case as my image(s) will end up with a white border around them which is quite visible given that my game's background is constantly changing.

Any ideas?

Thanks,Regards

+2  A: 

You call image.convert(). From the docs for Surface.convert:

"The converted Surface will have no pixel alphas. They will be stripped if the original had them. See *Surface.convert_alpha* - change the pixel format of an image including per pixel alphas for preserving or creating per-pixel alphas."

Kylotan