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

Re: [pygame] Create alpha surfaces



On Tue, 2005-09-13 at 16:08 +0200, Willem wrote:
> I've got a little problem with aplha surfaces. I'm trying to create a
> new surface which is completely TRANSPARENT to draw onto it antialiased
> text, and then return that surface to blit it onto another one, but what
> I get is a BLACK surface with the text correctly rendered which doesn't
> blit transparently at all. I found a very pathetic way of doing this:

When you create the Surface, include the SRCALPHA flag. This will pretty
much do what you want. The best way to test if the Surface really has
per pixel alphas is to see if there is an alpha mask.

size = 100, 100
surf_with_alpha = pygame.Surface(size, pygame.SRCALPHA, 32)
test_perpixel_alpha = surf_with_alpha.get_masks()[3] != 0

Also, in the case where you already have an image and want to add
perpixel alpha, you can call Surface.convert_alpha().