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

Re: [pygame] Simple Surfarray Alpha



Hi Ian,

There's not enough information to make a diagnosis. What was the error? Are you sure the surface has per-pixel alpha? What array package are you using? With NumPy and the latest Pygame I get no error:

>>> import pygame as pg
>>> s = pg.Surface((10,10), pg.SRCALPHA, 32)
>>> a = pg.surfarray.pixels_alpha(s)
>>> a[:,:] = 255 - a[:,:]
>>> del a
>>> s.get_at((0,0))
(0, 0, 0, 255)

Lenard


Ian Mallett wrote:
Hello,

I need to make a function where the alpha value of a surface is flipped. I can already do this with the red, green, or blue channels:

#red flip
array = pygame.surfarray.pixels3d(surface)
array[:,:,0] = 255-array[:,:,0]
del array

#green flip
array = pygame.surfarray.pixels3d(surface)
array[:,:,1] = 255-array[:,:,1]
del array

#blue flip
array = pygame.surfarray.pixels3d(surface)
array[:,:,2] = 255-array[:,:,2]
del array

#rgb flip
array = pygame.surfarray.pixels3d(surface)
array[:,:,:] = 255-array[:,:,:]
del array

I can't do the alpha flip though.  I tried:

array = pygame.surfarray.pixels_alpha(surface)
array[:,:] = 255-array[:,:]
del array

but it raises an error.

Ideas?
Thanks,
Ian


--
Lenard Lindstrom
<len-l@xxxxxxxxx>