how to save texture to file

hi,i create a deep buf,and want to save the image to file :
/************/
self.buffer = self.createOffscreenBuffer(-3,1024,1024)
self.depthmap = Texture()
self.buffer.addRenderTexture(self.depthmap, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)

        if(base.win.getGsg().getSupportsShadowFilter()):
          self.depthmap.setMinfilter(Texture.FTShadow)
          self.depthmap.setMagfilter(Texture.FTShadow)
        self.light = base.makeCamera(self.buffer)
        self.light.reparentTo(base.camera)
        self.light.node().setScene(render)
        self.light.node().getLens().setFov(60)
        self.light.node().getLens().setNearFar(10, 500)

        lci = NodePath(PandaNode("lightCameraInitializer"))
        lci.setShader(loader.loadShader("shadow/share/shaders/caster.sha"))
        self.light.node().setInitialState(lci.getState())

/************/

I tryed :

base.screenshot(filename,defaultFilename = 0,source=self.buffer)

or

self.depthmap.write(filename)

but couldn’t get the file

def createOffscreenBuffer(self,sort, sizex, sizey):
winprops = WindowProperties.size(sizex,sizey)
props = FrameBufferProperties()
props.setRgbColor(1)
props.setAlphaBits(1)
props.setDepthBits(1)
return base.graphicsEngine.makeOutput(
base.pipe, “offscreenBuffer”,
sort, props, winprops,
GraphicsPipe.BFRefuseWindow,
base.win.getGsg(), base.win)

and
/**********/

i=0
for iwin in range(base.graphicsEngine.getNumWindows()):
win = base.graphicsEngine.getWindow(iwin)
i=i+1
base.screenshot(namePrefix=filename+str(i)+".png",defaultFilename = 0,source=win)

/**********/

it work,but got 256256 deepmap file,not 10241024

You can use base.screenshot(source = self.buffer), instead of iterating through all of the windows to find self.buffer. Or, just use self.buffer.saveScreenshot(), which is all that base.screenshot() does (you can see the code for base.screenshot() in ShowBase.py).

If you want to save out the image from the texture, instead of from the buffer, then you have to use RTPCopyRam (which is slower) instead of RTPBindOrCopy.

Since the image is smaller than you expect, perhaps you are actually getting a ParasiteBuffer, which is constrained to be no larger than the window size?

David