Pygame Cross Platform Color Mismatch

I am trying to use get_atand set_atto change the colors of GIF images by searching for opaque pixels and changing them to the desired color.

It works fine on OSX machines, transparent colors are read as (0, 0, 0, 0)well and reoriented to everything that I choose. But when I start the Windows 7 machine, transparent pixels are read as (255, 255, 255, 0), causing the entire image to become tinted.

The code I use is as follows:

player_border_w, player_border_h = thisGame.ready_border.get_size()
for y in range(player_border_h):  # run for each image pixel
    for x in range(player_border_w):
        if thisGame.ready_border.get_at((x, y)) != TRANSPARENT:  # (0, 0, 0, 0)
            thisGame.ready_border.set_at((x, y), thisGame.ghost_colors[idx - 1])  # replace with desired color

Can anyone know what might cause this and any solutions?

Thanks!

+4
source share
1 answer

RGBA - (, , , ). , - - 0, , .

def is_transparent(colour):
    red, green, blue, alpha = colour
    if alpha == 0:
        return True
    return False

, :

def is_transparent(colour):
    return colour[3] == 0

, OSX Windows, , , , , .

+3

Source: https://habr.com/ru/post/1619889/


All Articles