[Python] How to save pygame Surface as an image to memory (and not to disk)

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am developing a time-critical app on a Raspberry PI, and I need to send an image over the wire. When my image is captured, I am doing like this:

    # pygame.camera.Camera captures images as a Surface
    pygame.image.save(mySurface,'temp.jpeg')
    _img = open('temp.jpeg','rb')
    _out = _img.read()
    _img.close()
    _socket.sendall(_out)


    This is not very efficient. I would like to be able to save the surface as an image in memory and send the bytes directly without having to save it first to disk.

    Thanks for any advice.

    EDIT: The other side of the wire is a .NET app expecting bytes

    Continue reading...

Compartilhe esta Página