I am using the http://sourceforge.net/projects/jlibeps/ library.
I have an existing Graphics2D object that is already drawn onto, and then want to create a new EpsGraphics2D object from the Graphics2D object.
Is this possible, or any suggestions on how to accomplish this?
The jlibeps author provided this example, but I fail to understand how the paint(g) line can accomplish this:
//If you want to paint a Graphics2D in an EPS file, you can do that:
FileOutputStream finalImage = new FileOutputStream(file);
EpsGraphics2D g = new EpsGraphics2D("Title", finalImage, 0, 0, 500, 500);
paint(g);
g.flush();
g.close();
finalImage.close();
Having a
Graphics2Dobject in general won’t help you, as it allows you to draw to some medium, but not to read what is currently rendered to that medium, much less what instructions were used to draw the current content.Instead, you have to feed a
EpsGraphics2Dobject into the pipeline just the same way you would aGraphics2Dobject for screen rendering. Usually you want to draw the content of some component. That can be done by calling itspaintmethod. So by calling thatpaintmethod with your constructed eps graphics object, you can cause all painting instructions to go to the eps file. That is what thepaint(g)line in the manual refers to.To phrase this differently: you do not need an existing
Graphics2Dobject which you magically turn into anEpsGraphics2Dobject. Instead, you need a chain of method calls which does something useful to aGraphics2Dobject, i.e. renders some content to it. Then you can re-use that code to generate an eps file by passing aEpsGraphics2Dobject (which is simply a special case of aGraphics2Dobject, and hence of aGraphicsobject) to the outermost invocation of that code.