png,jpg图像在pygame中无法正常显示(mac osx pycharm / IDLE)

时间:2016-04-19 08:26:11

标签: python macos pygame pycharm

最近在mac osx上使用pycharm / python IDLE开始用python编码。

当在定义的pygame显示器上显示/ blitting图像时,png和jpg格式不能正确显示(参见图像)。

只有bmp格式正确显示。

有什么建议让jpg和png在pygame中正确显示?

谢谢

source jpg image

how it appears on pygame display

import pygame, sys
    from pygame.locals import *

    pygame.init()

    width = 640
    height = 480

    screen = pygame.display.set_mode((width,height))
    pygame.display.set_caption('hello piggy')

    white = (255,255,255)
    image = pygame.image.load("flpig.jpg")

    x=160
    y=120

    running = True

    while running:
        screen.fill(white)
        screen.blit(image, (x, y))

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

        pygame.display.update()

1 个答案:

答案 0 :(得分:0)

import pygame
from pygame.locals import*
img = pygame.image.load("flpig.jpg")
white = (255, 255, 255)
w = 640
h = 480
screen = pygame.display.set_mode((w, h))
screen.fill((white))
running = 1

while running:
 screen.fill((white))
 screen.blit(img,(0,0))
 pygame.display.flip()