Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tinting an image in Pygame

Tags:

python

pygame

I'm looking on how to tint an image in Pygame in a similar fashion of how Monogame does it. I've been trying to get custom flags like BLEND_ADD to work but it's been hard to find concise examples of what I'm looking for, it's mostly been people trying to "darken" or work with the alpha levels in a way.

Question: How do I tint an image to a certain RGBA value in the same way that MonoGame does it?

like image 399
Quaz Avatar asked Feb 27 '18 17:02

Quaz


1 Answers

Fill your image with a color and pass one of the BLEND constants as the special_flags argument, e.g. your_image.fill((190, 0, 0, 100), special_flags=pygame.BLEND_ADD).

Note that BLEND_RGB_ADD is just an alias for BLEND_ADD (and the same applies to the other modes). The RGBA modes will also modify the alpha channel (ADD and MAX make transparent parts visible).

Here's a table that shows you the effects of the different blending modes (I've also added the names of the modes in Photoshop):

enter image description here

like image 142
skrx Avatar answered Nov 12 '22 17:11

skrx