且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Python 3.7 中使用 Pygame 显示装有 Pillow 的图像?

更新时间:2023-10-23 16:29:34

使用 Image.tobytes() 获取作为字节对象的图像数据和 pygame.image.fromstring() 将数据加载到 pygame.Surface 对象:

Use Image.tobytes() get the image data as a bytes object and pygame.image.fromstring() to load the data to an pygame.Surface object:

from PIL import Image
import pygame

pilImage = Image.open("myImageDirectory.png")
myImage = pygame.image.fromstring(pilImage.tobytes(), pilImage.size, pilImage.mode)