Hi all.
How can i use jogl to draw something and than, instead of display the result on a monitor, encode it to a jpeg ?
Hi all.
How can i use jogl to draw something and than, instead of display the result on a monitor, encode it to a jpeg ?
Here is how I save a canvas in jogl to jpeg.
public void saveImage() {
try {
saveDialog saveObj = new saveDialog();
String str; //string the will be the filename saved as
GraphicsConfiguration gc = saveArea.getGraphicsConfiguration();
//created buffered image of dimension same as plot to be saved
BufferedImage bimg = gc.createCompatibleImage(saveArea.getWidth(), saveArea.getHeight());
saveArea.paint(bimg.getGraphics()); //puts canvas into buffered image
//used to set str to string to be saved as
//the parameter 0 tells saveDialog XYPlot is being saved
str = saveObj.getFilename(0);
if (str != "null") {
File imageFile = new File(str);//here come up with own filename
ImageIO.write(bimg, "jpg", imageFile); //saves files
}
} catch (IOException ie) {
System.err.println("can't write jpg file");
}
please note saveArea is what is being saved and it is a GLJPanel.
Thanks a lot!!
Another little question, if i’m under linux, to use JOGL i must have an x-session started ?
[quote]Another little question, if i’m under linux, to use JOGL i must have an x-session started ?
[/quote]
Yes, at least currently. If you want to have almost-pure offscreen rendering, you can make a tiny borderless onscreen window, create a pbuffer from it, close the window, and use the pbuffer from then on.
Ok thanks,
but actually i don’t know what a pbuffer is, can you explain ?
[quote]Here is how I save a canvas in jogl to jpeg.
please note saveArea is what is being saved and it is a GLJPanel.
[/quote]
I’m using a GLCanvas instead of GLJPanel
GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
//created buffered image of dimension same as plot to be saved
BufferedImage bimg = gc.createCompatibleImage(500, 500);
canvas.paint(bimg.getGraphics());
try {
File imageFile = new File("C:\\test.png");
ImageIO.write(bimg, "png", imageFile);
} catch (IOException e) {
e.printStackTrace();
}
and the only result is a black square…
i’ve miss something?
Take a look at the links in this bug report for a couple of examples of taking screenshots and printing. The source code for the GLJPanel also shows how to read back the OpenGL frame buffer into a BufferedImage which you can then save using ImageIO.
[quote]Take a look at the links in this bug report for a couple of examples of taking screenshots and printing. The source code for the GLJPanel also shows how to read back the OpenGL frame buffer into a BufferedImage which you can then save using ImageIO.
[/quote]
Yes yes yes !! I’ve found what i need, thanks!!