2013-08-19 151 views
0

運行Python 3.3.0與pygame'1.9.2pre',遵循一個教程,新的python,誠實地不能看到我出了什麼地方,看起來像在教程上一樣,但它是4歲。感謝幫助!pygame.error不支持的圖像格式

我得到錯誤 - 兩種都不支持的圖像格式。我試過jpg和png,版本規範說它支持它們兩個。

bif ="bg.jpg" 
mif ="man.jpg" 
import pygame, sys 
from pygame.locals import * 

pygame.init() 

screen = pygame.display.set_mode((1100,750),0,32) 
background = pygame.image.load(bif).convert() 
mouse_c = pygame.image.load(mif).convert_alpha() 


Running = True 

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

    screen.blit(background,(0,0)) 

    x,y = pygame.mouse.get_pos() 
    x -= mouse_r.get_width()/2 
    y -= mouse_r.get_height()/2 

    screen.blit(mouse_r,(x,y)) 

    pygame.display.update() 
+0

什麼是'mouse_r'? – martineau

回答

0

我會假設由於代碼中的錯誤,pygame窗口沒有關閉。您可以退出python shell來退出pygame窗口,但錯誤是這裏的主要問題。

如果您像這樣導入圖像,請確保圖像與.py文件位於同一文件夾或位置 我不明白你從哪裏得到了mouse_r。

試試這個:

import pygame, sys 
from pygame.locals import * 



pygame.init() 



screen = pygame.display.set_mode((1100,750),0,32) 

background = pygame.image.load("bg.jpg").convert() 
mouse_c = pygame.image.load("man.jpg").convert_alpha() 

Running = True 

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

    screen.blit(background,(0,0)) 

    x,y = pygame.mouse.get_pos() 
    x -= screen.get_width()/2 
    y -= screen.get_height()/2 

    screen.blit(mouse_c,(x,y)) 

    pygame.display.update() 
+0

我仍然得到不支持的圖像格式。 – user2233480

+0

我可以推薦2個選項。完全刪除pygame並重新安裝使用此鏈接在這裏:http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame ...在哪裏你可以得到pygame python 3.3.0 ...打開你的圖像在圖像編輯器(xnView)中保存爲bmp圖像類型,這樣就可以不用麻煩地加載到pygame中 –

+0

不幸的是同一個錯誤信息 – user2233480

0

也許你已經在這裏使用了錯誤的變量名:

x,y = pygame.mouse.get_pos() 
x -= mouse_r.get_width()/2 
y -= mouse_r.get_height()/2 

screen.blit(mouse_r,(x,y)) 

我以前看過的same tutorial,似乎mouse_r應該是mouse_c

編輯:

嘗試使用完整的目錄路徑名,而加載圖像:

import os 
bif = os.getcwd() + "\\bg.jpg" 
mif = os.getcwd() + "\\man.jpg" 
+0

看來這裏真正的問題是pygame不會支持jpeg格式,因爲我的答案中的代碼也不起作用。 Pygame文檔指出,pygame只支持bmp圖像類型,如果不是用完整圖像支持構建的話。但這對我或其他人來說不是問題。問題是爲什麼? –

相關問題