SVG to BufferedImage?

Hi,
I have a lot of SVG files and want to load them and render them as BufferedImage (with transparent background) to be used as sprites. How do I do this?

I’ve read about the Batik project but didn’t find any good examples on how to do it.

I know I can convert SVG to GIF or PNG with various tools but I want to do the conversion on startup (to support different resolutions).

Any ideas or experience on this?

http://xml.apache.org/batik/

?

Take a look at:

batik-src-1.5.1/xml-batik/sources/org/apache/batik/apps/slideshow/Main.java

That’s basically the thing you want… minus the unnecessary stuff and with another image type (eg BufferedImage.TYPE_INT_ARGB).

Line 173:
image = renderer.getOffScreen();

is the thing which gives you the rendered (buffered) image.

So… some C&P and you’re done :wink:

http://koti.mbnet.fi/akini/java/png/svg2image/
Here is a simple example, it generates .jpg or .png images from .svg script files. See readme.txt for more info about how to configure batik libraries for this example.