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

Re: [pygame] using surfarrays without losing alpha?



On May 26, 2004, at 4:34 PM, Pete Shinners wrote:

Yeah, this is a pain. There are separate surfarray functions to deal with the alpha. Your softenRGBArray function looks like it would work directly on a single alpha array without any changes.
Here's what seems to work right now:

def softenImage(img):
rgbarray = pygame.surfarray.array3d(img)
transformedArray = softenRgbArray(rgbarray)
newImg = pygame.surfarray.make_surface(transformedArray).convert_alpha(img)
newImgAlphaArray = pygame.surfarray.pixels_alpha(newImg)
newImgAlphaArray[:,:] = pygame.surfarray.pixels_alpha(img)[:,:]
return newImg

I do the softening just as before, make the surface the same way as before, but now I copy the alpha values from the old surface to the new one. Seems like a roundabout way to do it, but I can't see any more straightforward way to do it at this point.

//jack