I have seen it cause SVG-Salamander is small enough to my projects. But I don't know if i can use it for that neither how to do it.
I've use this code :
public static void main(String[] args) throws IOException, SVGException {
// TODO Auto-generated method stub
File f = new File("./src/game_scheme.svg");
SVGUniverse svgUniverse = new SVGUniverse();
SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(f.toURL()));
BufferedImage bi = new BufferedImage(320, 240, BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
diagram.render(ig2);
ImageIO.write(bi, "PNG", new File("./yourImageName.png"));
}
But images are not smooth :( , any idea?
Yes, to load an SVG document using SVG Salamander:
BufferedImage
.Graphics2D
context from thatBufferedImage
.render()
onSVGDiagram
to draw the image.The process can be simplified using
SVGIcon
, which handles the Salamander internals, allowing the object to act as an ordinary SwingIcon
.To rasterize multiple SVG files on the command line, there's an Ant task for such conversions. See the documentation for details.
What follows is an example rasterizer that, given a path to an SVG resource file, will load and render a vector graphic onto a
BufferedImage
. No warranty, no support.SvgRasterizer.java
You'll also need the
ScalableDimension
andDimensionTuple
classes.ScalableDimension.java
DimensionTuple.java