Capture the glCanvas as a png file

hi all

i’m trying to do a capture of my display, and save it as a png file.

I have this code, but the png is empty (ie it’s a capture of the good size, but filled with the background color)
canvas is my glCanvas


Image image = canvas.createImage(canvas.getWidth(), canvas.getHeight());
ImageIO.write((RenderedImage)image, "png", new File("output/snapshot.png"));

any lead ?

If I remember correctly, Component#createImage only creates an image that is compatible with the component in question (i.e. same color depth, etc). It doesn’t create a snapshot of the contents of the component.
To get the image content you want you will have to use glReadPixels. An example usage is shown in this thread.

thx a lot :smiley: