PIL和PIL游戏机.imag

2024-09-29 01:31:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我用PIL打开了一个图像,比如

image = Image.open("SomeImage.png")

在上面画些文字,比如

^{pr2}$

然后保存为

image.save("SomeOtherName.png")

打开它游戏机.image在

this_image = pygame.image.load("SomeOtherName.png")

我只想不存钱就这么做。。有可能吗?保存和加载需要花费大量时间(0.12秒是的,这是因为我有多个图像需要此操作)。那个保存方法能被超越吗?在


Tags: 图像imagepilpngsaveloadopenthis
1条回答
网友
1楼 · 发布于 2024-09-29 01:31:49

您可以使用pygame.image中的fromstring()函数。根据文件,以下内容应有效:

image = Image.open("SomeImage.png")
draw = ImageDraw.Draw(image)
draw.text(Some parameters here)

mode = image.mode
size = image.size
data = image.tostring()

this_image = pygame.image.fromstring(data, size, mode)

相关问题 更多 >