In one of my projects I use JUNG2 to visualize a very large multiple-parent hierarchy graph, displayed in an applet. I would need to export the whole/parts of the graph to high resolution still images, since screenshots look hideous when printed (especially if the graph has been zoomed out).
The code I use currently is as follows:
public void writeToDisk(File saveToFolder, String filename) {
//Dimension loDims = getGraphLayout().getSize();
Dimension vsDims = getSize();
int width = vsDims.width;
int height = vsDims.height;
Color bg = getBackground();
BufferedImage im = new BufferedImage(width,height,BufferedImage.TYPE_INT_BGR);
Graphics2D graphics = im.createGraphics();
graphics.setColor(bg);
graphics.fillRect(0,0, width, height);
paintComponent(graphics);
try{
ImageIO.write(im,"png",new File(saveToFolder,filename));
}catch(Exception e){
e.printStackTrace();
}
}
This creates PNG images which are not particularly high resolution. So my questions are as follows:
- Is it possible to push up the PNG export resolution to 300 dpi?
- Is it possible to export the graph, or any swing component for that matter, to vector based formats such as EPS, PDF or SVG without too much hassle? I have found several libraries (VectorGraphics2D,FreeHEP) for managing vector based images in Java, however I am not sure if using them would mean that I have to "re-draw" each vertex and edge in the graph. That's obviously not very desirable...
- Are there any other alternatives which I might have missed?
Thanks in advance,