how to capture graphics primitives from Graphics2D

2019-05-21 08:15发布

I need to capture the graphics primitives from calls to java.awt.Graphics2D. The calls are made through an Open Source toolkit (Apache's PDFBox) and normally rendered in a JPanel. I would like to intercept these calls and translate them to SVG so I can build a non-graphics data model (e.g. tables, graphs, etc.). I'll be happy for any type of hack at this stage, which might include:

  • replacing the Graphics2D library with MyGraphics2D
  • Finding a Graphics2D that supported SVG output and capturing that
  • intercepting the calls to Graphics2D (I'd prefer not because I have to manage the affine transformations)

Subsidiary question: Does Graphics2D use the Graphics library? In which case if I capture at this level the transformations should have been applied.

2条回答
仙女界的扛把子
2楼-- · 2019-05-21 09:00

JFreeSVG is another option to consider, it provides a fast lightweight implementation of the Graphics2D API.

查看更多
ら.Afraid
3楼-- · 2019-05-21 09:03

I would have a look at the Batik project which provides an extension of Graphics2D to output SVG files.

查看更多
登录 后发表回答