不支持的图像格式 PyGame

Image format not supported PyGame

所以,我正在尝试更改我正在开发的游戏的 PyGame 图标。每当我 运行 代码时,它都会用 pygame.error: Unsupported image format

击中我

pygamewindow也用#Setting the game icon下的代码打开和关闭,当我没有这些代码时它没有这样做。

我一直在寻找一个好的答案,但找不到一个好的答案。如果有人有任何建议,我将不胜感激。

我正在使用 Python 3.10

在 Visual Studio 代码上编程

这是我的代码:

import time
import pygame

# Initializes Pygame
pygame.init()

# Game Screen Variables
background_colour = (255,255,255)


# Sets up the playscreen
screen = pygame.display.set_mode((1100,750),0,32)
pygame.display.set_caption("Dusco's Game")
screen.fill(background_colour)
pygame.display.flip()

# Setting the game icon
img = pygame.image.load('gameicon.png')
pygame.display.set_icon(img)


# Game Loop
running = True
while running:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False

pygame.quit ()

确保它是一个 PNG 并且你这样做了路径因为它是错误的试试这个:

img = pygame.image.load('c:/users/USERNAME/PATH_TO_IMAGE/gameicon.png')