错误:无法打开图像

时间:2013-09-26 12:23:03

标签: python image jpeg pygame

我正在使用pygame进行基于时间的移动计划。我一直收到这个错误。

Traceback (most recent call last):
  File "C:\Documents and Settings\Mohammad Raza\Desktop\Python     
Scripts\TimeBasedMovement.py", line 11, in <module>
    background = pygame.image.load(background_image_filename).convert()
error: Couldn't open Wolf.jpg

我想也许我删除了图片,但是我检查了图像并没有删除。它保存为名称“Wolf”并存储为JPEG图像。

以下是整个代码。

background_image_filename = 'Wolf.jpg'
sprite_image_filename = 'Cartoon.jpg'

import pygame
from pygame.locals import *
from sys import exit

pygame.init()
screen = pygame.display.set_mode((640,480),0,32)

background = pygame.image.load(background_image_filename).convert()
sprite = pygame.image.load(sprite_image_filename)

clock = pygame.time.Clock()

x = 0.
speed = 250

while True:

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

    screen.blit(background,(0,0))
    screen.blit(sprite,(x,100))

    time_passed = clock.tick()
    time_passed_seconds = time_passed_seconds / 1000.0

    distance_moved = time_passed_seconds * speed
    x += distance_moved

    if x > 640.:
        x -= 640.

    pygame.display.update()

2 个答案:

答案 0 :(得分:0)

还要确保图像位于当前工作目录中。

fullname = os.path.join('data', name)
     image = pygame.image.load(fullname)

答案 1 :(得分:-2)

也应该是

time_passed_seconds = time_passed / 1000.