更新时间: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)