无法在android上的pygame中打开图像 [英] Cannot open image in pygame on android

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

问题描述

我正在编写一个小游戏,我需要加载一些图像,但是当我加载图像时出现了意外错误,有人可以帮助我摆脱它这是这段代码

I am programming a mini game and I need to load some images but when I loaded images sone unexpected error raised can someone please help me to get out of it Here is this code

#-*-coding:utf8;-*-
#qpy:pygame

import sys
import pygame
from pygame.locals import *

pygame.init()
surface = pygame.display.set_mode((640, 480))
image = pygame.image.load("Audi.png").convert()
clock = pygame.time.Clock()

while True:
    for ev in pygame.event.get():
         if ev.type == QUIT:
            pygame.quit()

   clock.tick(60)
   surface.fill((0, 0, 0))
   surface.blit(label, (0, 0))
   pygame.display.flip()

我得到的错误是在这个

And error which I am getting is in this

推荐答案

图像文件路径必须相对于当前工作目录.工作目录可能与python文件的目录不同.

The image filepath has to be relative to the current working directory. The working directory is possibly different to the directory of the python file.

文件名和路径可以通过__file__.当前工作目录可以通过 os.getcwd() 获取.

The name and path of the file can be get by __file__. The current working directory can be get by os.getcwd().

如果图像与python文件在同一个文件夹中,则cab获取文件的目录并连接图像文件名.例如:

If the image is in the same folder as the python file, then you cab get the directory of the file and concatenate the image filename. e.g.:

import sys
import pygame
from pygame.locals import *
import os

# get the directory of this file
sourceFileDir = os.path.dirname(os.path.abspath(__file__))

# [...]

image = pygame.image.load( os.path.join(sourceFileDir, "Audi.png") ).convert()

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

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