[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pygame surface



On 09/09/2014 04:57 AM, diliup gabadamudalige wrote:

How can a Pygame surface be converted to an image file say a jpeg or a png WITHOUT writing the file to disk? Say after a screen grab?



It is not highly documented, but you can pass a file-like object to pygame.image.save. So instead of a filename you could create a StringIO buffer and write into that. Or you could use something crazy like an html post request and upload directly to a website.

If you are trying to load the image into a different library, it will be easier to use the "tobuffer" or "tostring" methods on the Surface. Then hope the other library you are using has a fromstring, frombuffer, or fromdata style function.