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

Re: [pygame] .png saving



Ian Mallett wrote:
On 10/26/07, *Pete Shinners* <pete@xxxxxxxxxxxx <mailto:pete@xxxxxxxxxxxx>> wrote:

    Pygame should be able to save from OpenGL without any changes.

Try this in an OpenGL program:

keystate = pygame.key.get_pressed()
if keystate[K_s]: #"s" is for screenshot
        pygame.image.save(surface, "1.jpg")

...crashes, where:

surface = pygame.display.set_mode((screen[0], screen[1]), OPENGL|DOUBLEBUF)

Ian
here's what I use to take OpenGL screenshots, making use of PIL to save to .png:
|
import pygame
import Image as PILImage

||def saveScreenShot( self ):
   timeName = time.strftime( '%m%d-%H%M%S', time.localtime() )
saveImage( pygame.display.get_surface(), 'Temp/ScreenShots/%s_screen.jpg' % timeName )

def saveImage( surface, filePath ):
pilImage = PILImage.fromstring( 'RGBA', surface.get_size(), pygame.image.tostring( surface, 'RGBA' ) )
   fileDir  = os.path.dirname( filePath )
   if not os.path.exists( fileDir ):
       os.makedirs( fileDir )
   pilImage.save( filePath )|

-Jasper