PIL 和 pygame.image [英] PIL and pygame.image
本文介绍了PIL 和 pygame.image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 PIL 打开了一个图像,如
I had opened an image using PIL, as
image = Image.open("SomeImage.png")
在上面画一些文字
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屋!
查看全文