首页 > 解决方案 > 我无法将“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

在此处输入图像描述

标签: pythonimagepygame

解决方案


如果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

推荐阅读