python-3.x - 无法通过 Pygame 的 Image.load() 打开图像
问题描述
我的 pygame 程序似乎没有加载图像。我通过直接输入图像路径以及加入目录来尝试 image.load() 。我在 Sublime Text 和 IDLE 上尝试了代码。文件来源:C:\Users\Aich\Documents\PythonProjects\Trial 图片来源:C:\Users\Aich\Desktop\Sprite1.png (我目前将图像和文件保存在不同的位置,但没有将它们保存在同一位置产生任何东西)
我正在使用 Windows 8.1。
import pygame
pygame.init()
white = (255, 255, 255)
x = 500
y = 400
display_surface = pygame.display.set_mode((x,y))
pygame.display.set_caption('Image')
image = pygame.image.load(r'C:\Users\Aich\Desktop\Sprite1.png').convert()
while True:
display_surface.fill(white)
display_surface.blit(image , (0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
pygame.display.update()
解决方案
推荐阅读
- java - 为我的 Deque 引用数组索引时,我不断收到 NullPointerException
- google-sheets - 谷歌表格中的“忽略”暗/亮模式
- hough-transform - Houghlines 无法找到清晰可见的单线
- python - 如果 linux 中的活动窗口发生变化,则执行 python 代码
- go - 从子文件夹导入函数
- python - 如何在 python 中有效地存储、检查包含和检索大量浮点数?
- ios - 使用 Rect Native RNIAP 包启动 App Store 应用内购买对话框为时已晚
- algorithm - Google Kickstart Round A 2021-Rabbit House
- ibm-midrange - 基于条件的命令参数填写提示
- amazon-web-services - 在本地运行由 cdk 创建的嵌套堆栈