I had opened an image using PIL, as
JavaScript
2
1
image = Image.open("SomeImage.png")
2
Draw some text on it, as
JavaScript
3
1
draw = ImageDraw.Draw(image)
2
draw.text(Some parameters here)
3
and then saved it as
JavaScript
2
1
image.save("SomeOtherName.png")
2
to open it using pygame.image
JavaScript
2
1
this_image = pygame.image.load("SomeOtherName.png")
2
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?
Advertisement
Answer
You could use the fromstring()
function from pygame.image
. The following should work, according to the documentation:
JavaScript
10
1
image = Image.open("SomeImage.png")
2
draw = ImageDraw.Draw(image)
3
draw.text(Some parameters here)
4
5
mode = image.mode
6
size = image.size
7
data = image.tostring()
8
9
this_image = pygame.image.fromstring(data, size, mode)
10