Fwd: Re: Expyriment - picture and alpha level

24 views
Skip to first unread message

Oliver Lindemann

unread,
Feb 15, 2016, 2:55:43 AM2/15/16
to expyrime...@googlegroups.com

Dear Clement,

Sorry that getting back to you took so long.

The reason why your example does not work is that the surfaces in Expyriment use per-pixel alpha, in order to support transparent backgrounds. As noted in the Pygame documentation (http://www.pygame.org/docs/ref/surface.html#pygame.Surface.set_alpha) surface alpha settings are not compatible with per-pixel alpha and will hence be ignored.

A solution would be to first remove the surface alpha with set_alpha (None) and then proceed as in yout example. Keep in mind, however, that this will also remove any transparent backgrounds in your images, if present.

If you want images with transparent backgrounds without surface alpha, things are more complicated and a solution might depend on the content of the pictures. E.g. if you could try to give the background a unique colour and then set the colorkey to that colour (http://www.pygame.org/docs/ref/surface.html#pygame.Surface.set_colorkey) to that colour.

If this is not possible I'm afraid that Pygame cannot do this and you have to prepare the images in an image processing software beforehand.

I hope this helps.

Best,
Florian

On 9 Feb 2016 16:12, "Clément Moutard" <clement...@polytechnique.org> wrote:
Dear Oliver and Florian,

I would like first to thank you really much for the nice and useful library - Expyriment - you have developed.
I also have an issue in the implementation of a paradigm.
I need to present two overlapping visual stimuli. So I need to change the alpha of the pictures.
I did not find a way to do it directly in Expyriment, but I know it is possible via pygame.
However, I have never managed to change the transparancy in expyriment (tested with and without OpenGL).
Below is a piece of my code :

stim = stimuli.Picture(filename)
surf = stim.get_surface_copy()
surf.set_alpha(125)
stim.set_surface(surf)

Any clue ? 
In advance, thank you really much.
Best,

Clément


Reply all
Reply to author
Forward
0 new messages