Python Forum
display error, png with transparent background
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
display error, png with transparent background
#1
Dear community,

I display a paddle and a ball in a breakout game.

I've got an error concerning the display of the paddle.

Both pictures (ball + paddle) have got a transparent background.

The ball is displayed correctely - the paddle not (it has a white rectangle as background).

Online I read that I have to you use "convert_alpha()" to display pictures with a transparent background...

I attached ball.png and paddle.png.
In addition to that I attached the wrong display.

Would you please have a look at these files and perhaps tell me what's wrong with paddle.png?
def create_image(file, color=None):
    """
    Create image from a file.  If color is specified, replace all FOREGROUND
    pixels with color pixels.  Modify image so TRANSPARENT colored pixels are
    transparent.
    """
    if color:
        # Recolor the image
        image = Image.open(file).convert("RGB")
        for xy in product(range(image.width), range(image.height)):
            if image.getpixel(xy) == FOREGROUND:
                image.putpixel(xy, color)
        image = pygame.image.fromstring(image.tobytes(), image.size, "RGB")
    else:
        image = pygame.image.load(file)
    image.set_colorkey(TRANSPARENT)
    return image.convert_alpha()

Attached Files

Thumbnail(s)
       
Image(s)
   
Reply


Messages In This Thread
display error, png with transparent background - by flash77 - Mar-13-2022, 09:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [pygame] transparent rects SheeppOSU 2 2,353 Jun-10-2019, 03:41 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020