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

Re: [pygame] Blitting to alpha channel or using another image's alpha channel



I've had good luck using colorkey blitting, if the mask is just binary, and if you have a color you know isn't in the image you want to blit. For example, if you know the image doesn't have any magenta, blit the mask in magenta over black, set the color key to black, then blit the mask onto the image, then set the color key of the image to pink, and then blit the image. Don't know if this is better or worse than the other approaches people have mentioned.

--Mike

Weeble wrote:
Can somebody suggest how to do this? I want to render parts of an
image based on a dynamically generated mask. Right now I'm doing this
by drawing the mask in black and white on another surface, then
iterating over every pixel and changing the alpha value of the source
image to match the red value of the corresponding pixel in the mask
surface, then finally blitting this onto the target surface. This
seems a bit convoluted and I get the feeling there's probably a more
efficient way to do it. Is there a way either to 1. blit an 8-bit
greyscale image directly into the alpha channel of an image, or 2.
directly blit image A onto image B using image C as the alpha channel?