Skip to content Skip to sidebar Skip to footer

Convert A Pygame Surface Into An Image?

is there a way to convert a pygame surface into a png image? rgb_content = pygame.surfarray.array2d(canvas) cv2.imwrite(file, rgb_content, [cv2.IMWRITE_PNG_COMPRESSION, 0]) I've t

Solution 1:

Use the save function of the image modul:

pygame.image.save()
save an image to disk
save(Surface, filename) -> None

This will save your Surface as either a BMP, TGA, PNG, or JPEG image. If the filename extension is unrecognized it will default to TGA. Both TGA, and BMP file formats create uncompressed files.

So just use it like this:

pygame.image.save(your_surface, "your_filename.png")

Post a Comment for "Convert A Pygame Surface Into An Image?"