SVG (Scalable Vector Graphics) defines a vector graphic format based on XML schema. The Batik SVG Toolkit provides to use SVG graphics in Java. For example to generate SVG graphics as images or for embedding SVG graphics in user interface dialogs. The following example describes how to convert a SVG file to an PNG file.
//retrieve the parse class name
String parserClassName = XMLResourceDescriptor.getXMLParserClassName();
//initialize the document factory
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
//instance an existing SVG file
Document doc = f.createDocument("file://" + svgFile);
//use the PNG transcoder
ImageTranscoder transcoder = = new PNGTranscoder();
String svgURLPath = new File(svgsource).toURL().toString();
TranscoderInput input = new TranscoderInput(svgURI);
OutputStream outputStream = new FileOutputStream("logo.png");
TranscoderOutput output = new TranscoderOutput(outputStream);
//converting method to PNG file
transcoder.transcode(input, output);
outputStream.flush();
outputStream.close();
Regards
Rafael Sobek
