[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] convert() bug?



thanks for sending the example and file - it looks like Ethan was
correct about what's going on. Most places where the image is
transparent, it is transparent-white. The bottom line is
transparent-black. You didn't notice the transparency being removed
anywhere but the black line because in your example the background is
white. This modified simple example should make all this clearer
(magic pink background, multiple versions of beach ball image drawn):

import pygame, sys
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255, 0, 255])
my_ball_original = pygame.image.load("beach_ball.png")
my_ball_convert = my_ball_original.convert()
my_ball_convert_alpha = my_ball_original.convert_alpha()
screen.blit(my_ball_original,[50, 50, 90, 90])
screen.blit(my_ball_convert,[150, 50, 90, 90])
screen.blit(my_ball_convert_alpha,[250, 50, 90, 90])

my_ball_remove_column_alpha = my_ball_original.convert_alpha()
for y in xrange(my_ball_remove_column_alpha.get_height()):
    pos = (0, y)
    pixel = my_ball_remove_column_alpha.get_at(pos)
    pixel = (pixel[0], pixel[1], pixel[2], 255)
    my_ball_remove_column_alpha.set_at(pos, pixel)
screen.blit(my_ball_remove_column_alpha,[350, 50, 90, 90])

pygame.display.flip()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()


On Dec 28, 2007 7:10 AM, hwg <hwg434@xxxxxxxxx> wrote:
>
> This displays a beach ball image.
> Oddly, the black is only a line at the bottom. If it was related to
> transparency, I would expect there to be black all around the ball
> If I remove the line that uses convert(), the black line goes away.  I tried
> convert_alpha, and that works as well, but the black line still puzzles me,
>
> hwg
>
>
> ----- Original Message ----
> From: Ethan Glasser-Camp <glasse@xxxxxxxxxx>
> To: pygame-users@xxxxxxxx
> Sent: Monday, December 17, 2007 4:50:02 PM
> Subject: Re: [pygame] convert() bug?
>
> Can you send the image? It sounds like there's a one-pixel thick line
> along the bottom of the image which is fully transparent. Since
> convert() removes transparency, the line becomes visible. If that is
> the case, you could consider using convert_alpha() to preserve alpha
> (and thus transparency on that one-pixel-thick line).
>
> Ethan
>