Feb-14-2017, 04:36 PM
I have an image of a white robot. How can I change the color white of that image to another color, like red or blue or green or something?
Happy Valentine's
Happy Valentine's

[PyGame] image color
|
||||
Feb-14-2017, 04:36 PM
I have an image of a white robot. How can I change the color white of that image to another color, like red or blue or green or something?
Happy Valentine's ![]()
Feb-14-2017, 08:22 PM
Once you've loaded the image as a surface, then you can access that surface's pixels with a PixelArray. The PixelArray class has a replace method, which replaces all instances of one color with another (so you don't need to check individual pixels yourself). When you create a PixelArray, it locks the underlying surface until it's garbage collected, so you should delete it when you're done (or use a function and return from it).
http://www.pygame.org/docs/ref/pixelarra...ay.replace So...
Feb-26-2017, 11:50 PM
could I replace the color with an alpha value? I want to change white to clear.
Feb-27-2017, 12:01 AM
Absolutely :)
Color() takes for arguments, rgba. If you pass 0 as the final parameter, then it should be fully transparent (and the other three parameters wouldn't matter at that point).
Feb-27-2017, 12:09 AM
I tried that. it ignored the final value
Feb-28-2017, 06:30 PM
What about Surface.set_colorkey()?
https://www.pygame.org/docs/ref/surface....t_colorkey Wrote:Set the transparent colorkey So, if you set the colorkey to whatever color you want to be transparent, that... might... work?
Mar-03-2017, 01:34 AM
I made a script to show this example. Without the image you are using i can only use an example image
You can change which color is the transparent by change the from_ color. And it shows as white as the background is white before the image is drawn.
Recommended Tutorials:
| ||||
|