Python Forum
Coloring a surface with transparency - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: Coloring a surface with transparency (/thread-35920.html)



Coloring a surface with transparency - Sandor - Dec-29-2021

Hello all,

I am completely new here, I hope my question is correct here. I am programming a football manager game and would like to add a selection of a jersey color. The RGB colors are completely free selectable and a jersey should be colored in exactly this color.

My first approach was to load a white jersey with transparent background as Surface, and fill it with the desired color. However, I then only get a square box with the color, obviously the transparent pixels are also filled with the color. In addition, the black pixels (folds in the jersey) were also colored.

My goal is to have a jersey filled with the desired color, but still have a transparent background. I would be very happy about any hints or suggestions for solutions.

I am using Pygame.

Many greetings
Sandor


RE: Coloring a surface with transparency - menator01 - Dec-29-2021

A couple of links from duckduckgo search
https://stackoverflow.com/questions/39932138/make-the-background-of-an-image-transparent-in-pygame-with-convert-alpha
https://www.codegrepper.com/code-examples/python/pygame+transparent+background


RE: Coloring a surface with transparency - Sandor - Dec-29-2021

Thanks for the links, which unfortunately did not help much, but I actually found a first solution myself. I took a transparent jersey (only the outlines and single folds are visible) and checked with "get_at" every pixel for transparency, and if there is none, I colored the pixel with "set_at". At the end I drew the transparent jersey again and it looks very good.

But now I draw two images directly one after the other, once the colored jersey and once the transparent jersey. Is there a way to "save" a surface onto another surface, so that I have the finished jersey saved in a single variable?


RE: Coloring a surface with transparency - Sandor - Dec-29-2021

See attached the jersey, which consists of two graphics on the right side (excluding the pitch of course, the blue jersey is completely filled with the desired color and the transparent jersey is drawn above that to get that effect. Now I want these final graphic of the jersey saved in one variable).

[attachment=1503]


RE: Coloring a surface with transparency - Sandor - Jan-02-2022

nevermind