PIL和pygame.image [英] PIL and pygame.image

查看:85
本文介绍了PIL和pygame.image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用PIL打开了图片,

I had opened an image using PIL, as

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

在上面画一些文字,就像

Draw some text on it, as

draw = ImageDraw.Draw(image)
draw.text(Some parameters here)

,然后将其另存为

image.save("SomeOtherName.png")

使用pygame.image打开它

to open it using pygame.image

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

我只想不保存就做.可以吗?保存然后加载需要大量时间(0.12秒,是的,因为我有多个需要此操作的图像,因此需要更多时间).可以超越那种保存方法吗?

I just want to do it without saving.. Can that be possible? It is taking a lot of time to save and then load(0.12 sec Yes, that is more as I have multiple images which require this operation). Can that save method be surpassed?

推荐答案

您可以使用pygame.image中的fromstring()函数.根据文档,以下内容应该起作用:

You could use the fromstring() function from pygame.image. The following should work, according to the documentation:

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)

这篇关于PIL和pygame.image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆