Save image from buffer ram

hi, guys, I am trying to get the texture from buffer and save it to .png, At first, I use a screenshot func but get a image with a poor quality. After ensuring the buffer.hasTexture() == True, I try to use buffer.getTexture().write(filepath) to save the pic. However, I got the error message like this:
AssertionError: do_has_ram_mipmap_image(cdata, n) at line 4958 of panda/src/gobj/texture.cxx
Could you tell me how to solve this? or if there are another methods to save a raw picture from ram?
Thanks :smiley:

Hi, welcome to the forum!

How have you attached the texture to the buffer? You may need to attach it with a mode that forces it to be copied from the GPU RAM to your system RAM, or otherwise, an explicit call to extractTextureData is needed to transfer it.

Thanks for your quick reply! I followed your instruction and do this:

        tex = Texture()

It still doesn’t work. The altBuffer is created from“hello”, self.config[“minimap_length”], self.config[“minimap_width”]).
This is a buffer is used to show a bird-view minimap of my racing game.
Now I want to save these minimaps from the camera of altBuffer.
This problem is really confused :sweat:

hi, bro, I used a trick to got the image with a high quality instead of accessing the ram or gpu ram. I simply call graphicsEngine.flipFrame() and then saveScreenshot(), then it works!!! And I am curious about the difference between filpFrame() and renderFrame(), why the later one didn’t draw each part of a scene? Did you do some optimization to accelerate the render process? It’s really interesting!!

For what it’s worth, extractTextureData can only be used after the texture first actually has data in GPU RAM, for which you would still need to use or something of the sort first.

However, if you got saveScreenshot to work, that is most convenient.