2016-05-21 40 views
0

我試圖從不在起始目錄中的文件加載圖像。
到目前爲止,我有:從不同目錄加載png圖像Python Pygame

BG_f = open("pictures/adventure background.png","r") 

後來我想這個圖像BitBlt到屏幕上,但我得到:

screen.blit(BG_f,(0,0)) 
TypeError: argument 1 must be pygame.Surface, not file 

於是我嘗試:

BG = pygame.image.load(BG_f) 

但只返回:

libpng error: PNG file corrupted by ASCII conversion 
... 
pygame.error: Error reading the PNG file. 

顯然我做錯了什麼。我試圖查看如何,但我只能找到如何加載圖像在起始目錄。我只需要最基本的語法;我不太流利的python,sys或os(如果這些是必要的)。

回答

0

DUH我在做這一切錯,只是嘗試:

BG = pygame.image.load("pictures/adventure background.png") 

和它的工作! NVM