Using Batik to obtain a BufferedImage of an SVG
Posted on 2003-03-27
We have a project which requires us to us SVG files as icons. We want to render the SVG to BufferedImages to allow the one time render of the Icons (the icons will not animate during their lifetime on the screen). We have investigated ways of trying this, and have kinda hit our heads against a brick wall. We have tried using JSVGCanvas, and using the get offscreen method provided, which does work, but that means for each icon, we have the bloat of a JSVGCanvas to contend with, which is not a good thing. We then looked at a way of using just one JSVGCanvas as a render platform for all icons, which was a better solution, but not ideal, as we don't need the full bloat of swing, just the SVG image rendered into a BufferedImage. Next we looked at ways of using the Rasterizer App, which rasterizes SVG to Jpeg etc... which is almost what we after, and sure enough, inside the code of JPEGTranscoder, it actually uses a BufferedImage to render, then saves this to JPEG file. We tried creating our own BufferedImageTranscoder, but fell over quite early.
Has anybody got any solutions to offer. Big money (ok points) is on offer!