Load image from string
Posted
by zaf
on Stack Overflow
See other posts from Stack Overflow
or by zaf
Published on 2010-05-27T07:29:24Z
Indexed on
2010/05/27
7:31 UTC
Read the original article
Hit count: 220
Given a string containing jpeg image data, is it possible to load this directly in pygame?
I've tried using StringIO but failed and I don't completely understand the 'file-like' object concept.
Currently, as a workaround, I'm saving to disk and then loading an image the standard way:
# imagestring contains a jpeg
f=open('test.jpg','wb')
f.write(imagestring)
f.close()
image=pygame.image.load('test.jpg')
Any suggestions on improving this so that we avoid creating a temp file?
© Stack Overflow or respective owner