简体   繁体   中英

Create EpsGraphics2D from Graphics2D

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 Graphics2D object 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 EpsGraphics2D object into the pipeline just the same way you would a Graphics2D object for screen rendering. Usually you want to draw the content of some component. That can be done by calling its paint method. So by calling that paint method with your constructed eps graphics object, you can cause all painting instructions to go to the eps file. That is what the paint(g) line in the manual refers to.

To phrase this differently: you do not need an existing Graphics2D object which you magically turn into an EpsGraphics2D object. Instead, you need a chain of method calls which does something useful to a Graphics2D object, ie renders some content to it. Then you can re-use that code to generate an eps file by passing a EpsGraphics2D object (which is simply a special case of a Graphics2D object, and hence of a Graphics object) to the outermost invocation of that code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM