开发者

Load image from string

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开发者_如何学Python a temp file?


fstr = cStringIO.StringIO(simage)
pygame.image.load(fstr, namehint="somethinguseful")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜