Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export JPanel to vector graphics

I would like to export the image in my JPanel to a vector graphics file so it can be edited and printed at a higher-than-screen resolution. Essentially I want its paint() function to be called with a destination Graphics that saves the drawing commands into a vector graphic file.

What is a good, simple way to do this? What libraries are recommended? Which vector format would be best, and why?

like image 896
Carl Manaster Avatar asked May 01 '09 15:05

Carl Manaster


2 Answers

Have a look at The Java EPS Graphics2D package.

Many Java programs use Graphics2D to draw stuff on the screen, and while it is easy to save the output as a png or jpeg file, it is a little harder to export it as an EPS for including in a document or paper.

This package makes the whole process extremely easy, because you can use the EpsGraphics2D object as if it's a Graphics2D object. The only difference is that all of the implemented methods create EPS output, which means the diagrams you draw can be resized without leading to any of the jagged edges you may see when resizing pixel-based images, such as JEPG and PNG files.

like image 161
Pierre Avatar answered Oct 14 '22 13:10

Pierre


Apache Batik will let you paint to a specialised implementation of a Graphics2D object and then export as an scalable vector graphics (.svg) file. You can then view/process/print it using an SVG-enabled browser (Firefox will handle it nativly, ISTR, IE and others can use plugins).

See the SVGGraphics2D object (process documented here)

like image 6
Brian Agnew Avatar answered Oct 14 '22 12:10

Brian Agnew