Images distorted using pygame

2019-08-08 11:59发布

问题:

Trying to build my first pygame project and wanted to import the following map. Used image:

My code is:

import pygame
pygame.init()
size = (1300, 700)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("My Game")
done = False
clock = pygame.time.Clock()
map = pygame.image.load('map.jpg')
map = map.convert()
map = pygame.transform.scale(map, (466,700))
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
    screen.fill((255,255,255))
    screen.blit(map, (430, 0))
    pygame.display.flip()
    clock.tick(60)
pygame.quit()

and the output looks like:

I have also tried converting the jpg to a bmp but still the same results. I cannot figure out what is distorting the image, trying with other images it appears that the outputted images is slightly wider than the original. I suspect that pygame is just reading the width wrong and then putting the pixels into an array with that width.

Any advice on fixing this would be much appreciated.

回答1:

There is a bug in SDL_image (which Pygame is based on) that corrupts images in OS X 10.11.

https://bugzilla.libsdl.org/show_bug.cgi?id=3154

Currently, the only known workaround is to downgrade to SDL_image 1.2.10, but I have not been able to confirm.