错误:无法打开图像 [英] error: Couldn't open Image

查看:127
本文介绍了错误:无法打开图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pygame开发基于时间的移动程序。我一直收到这个错误。

I'm working on a time based movement program in pygame. And I keep receiving this error.

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图像。

I thought perhaps I deleted the image, but I checked and the image is not deleted. It is saved as the name "Wolf" and stored as a JPEG image.

以下是完整代码。

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()


推荐答案

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

Also make sure the image is in the current working directory.

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

这篇关于错误:无法打开图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆