Saving a screen shot?

Hi there, I am trying to save an screenshot using the following code:

			x = base.win.getXSize() 
			y = base.win.getYSize()
			print str((x, y))
			buffer = base.win.makeTextureBuffer('offscreen', x, y)
			img = PNMImage()
			buffer.getScreenshot(img)
			if(img.write(Filename("simulation_"+strftime("%d_%b_%Y_%H:%M:%S", localtime()))) == False):
				print("Error saving file.")

It always prints error, but never tells me what error it is, the x an y are ok (800, 600). Any ideas?

Thanks in advance.

Why not use Showbase’s screenshot function? 8)

Worked perfectly thank you.