【发布时间】:2012-04-09 05:42:01
【问题描述】:
所以,我从 mac Lion 中的 python 开始,我正在尝试使用图像制作我的第一个程序: 这是程序的代码
import pygame, sys
from pygame.locals import *
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((400, 300), 0, 32)
pygame.display.set_caption('Animation');
WHITE = (255, 255, 255)
catImg = pygame.image.load("cat.png")
catx = 10
caty = 10
direction = 'right'
while True:
DISPLAYSURF.fill(WHITE)
if direction == 'right':
catx += 5
if catx == 280:
direction = 'down'
elif direction == 'down':
caty += 5
if caty == 220:
direction = 'left'
elif direction == 'left':
catx -= 5
if catx == 10:
direction = 'up'
elif direction == 'up':
caty -= 5
if caty == 10:
direction = 'right'
DISPLAYSURF.blit(catImg, (catx, caty))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(FPS)
程序运行时出现错误:
Traceback (most recent call last):
File "catanimation.py", line 13, in <module>
catImg = pygame.image.load("cat.png")
pygame.error: File is not a Windows BMP file
这个问题的原因可能是什么
INFO:我使用了表面而不是图像,效果很好。我怀疑这个问题可能与我的 pygame 安装有关,但我不确定
【问题讨论】:
-
很确定 Lion 是 osx 10.7。错误消息声称该文件不是有效的 Windows 样式 BMP 格式。这就是你应该检查的。您是如何生成图像的?
-
我刚从网上下载的inventwithpython.com/cat.png
-
也许您应该将文件扩展名保留为“png”并将其作为 png 读取,而不是作为 bmp 读取。将 png 视为 bmp 将不起作用。
-
一开始是这样的,我试着这样读,但它没有用,所以我在我的机器上更改了名称,但我也没有工作
-
第一种方法是正确的方法,你应该发布你的错误信息。现在,你问我们为什么你把封面换成俄语后,俄语阅读机就不能阅读你的英文书了。