# Pixelated and incomplete image when loading with pygame.image.load

This is the image I'm trying to load on the surface, an 40x40 Ubuntu logo:

Ans this is how it looks when trying to show the image on the surface via the blit method:

I'm trying to load different Linux logos, the majority have PNG extension and a couple of GIF. The Ubuntu logo is a PNG image, it's weird that the other PNG and GIF images load just fine (Ubuntu and Kubuntu logo are the exceptions, they look pixelated and incomplete).

This is how my code looks like (I'm just starting with pygame):

#-*- coding: utf-8 -*-
import sys
import os
import random
import pygame
from pygame.locals import *

PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
LOGOS_DIR = os.path.join(PROJECT_DIR, 'data/images/logos')
WINDOW_WIDTH = 640
WINDOW_HEIGTH = 480
FPS = 30

# Colors
WHITE = (255, 255, 255)

BACKGROUND_COLOR = WHITE

pygame.init()
MAIN_SURFACE = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGTH))
CLOCK = pygame.time.Clock()

def get_linux_logos():
logos = []
for img in os.listdir(LOGOS_DIR):
try:
logos.append(pygame.image.load(os.path.join(LOGOS_DIR, img)))
except pygame.error, e:
continue
random.shuffle(logos)
return logos

def main():
pygame.display.set_caption('Geezle - Memory Puzzle')
MAIN_SURFACE.fill(BACKGROUND_COLOR)
LINUX_LOGOS_IMGS = get_linux_logos()[:12]

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

MAIN_SURFACE.blit(LINUX_LOGOS_IMGS[0], (300, 220))
pygame.display.update()
CLOCK.tick(FPS)

if __name__ == '__main__':
main()


## 1 Answer

Images with an alpha channel require an extra step of conversion when loaded. Instead of:

logos.append(pygame.image.load(os.path.join(LOGOS_DIR, img)))


Try the following:

logos.append(pygame.image.load(os.path.join(LOGOS_DIR, img)).convert_alpha())

• It's kinda weird that when I load a single Ubuntu image it looks ugly but when I load them in a row next to each other they look just fine (without the convert_alpha) – César May 25 '12 at 16:28