python - 我无法将“bmp”和“png”图像导入我的 pygame,
问题描述
这是我的问题,我一直在尝试将“bmp”图像导入为我的图标,但是当我运行它时,它却说pygame.error: Unsupported image format
。我已经尝试过 bmp 和 png 格式,但它们都不起作用。我很确定该文件与main
.
import pygame
pygame.init()
#Screen
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Space Invader")
#Title and Icon
icon = pygame.image.load('ufo.bmp')
pygame.display.set_icon(icon)
running = True
while running:
for event in pygame.event.get():
if event == pygame.QUIT:
running = False
解决方案
如果png图像与游戏在同一个文件中,您是否检查过您也可以尝试单击图像并复制其访问路径并用它替换ufo.bmp。或者只是尝试像这里一样为图标添加重音并添加文件格式:
import pygame
pygame.init()
#Screen
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Space Invader")
#Title and Icon
icon = pygame.image.load('ufo.bmp')
pygame.display.set_icon('icon.bmp')
running = True
while running:
for event in pygame.event.get():
if event == pygame.QUIT:
running = False
推荐阅读
- javascript - Angular2 +整个DOM在组件加载ngFor上闪烁
- java - 如何通过对象变量字符串对对象的arraylist进行排序
- sql-server-2008 - 删除空列并合并行
- r - 使用向量中的值和名称对数据框进行子集化的简单有效方法
- android - 想要确定哪个提供商在 android 中为我提供位置(无论是 gps 还是蜂窝/wifi 网络)
- r - maps::map() 返回地区名称而不是国家名称
- django - Elastic Beanstalk - 实例上的命令失败。发生意外错误 [错误代码:0000000001]
- c++ - 您应该使用 openssl 作为命令行还是将库编译到编程项目中?
- smalltalk - 如何在 Squeak FFI 中引用外部全局变量
- javascript - 如何在 Google(Places)API 中放置多个输入参数