January 24, 2010

Java SVG Example

« Java Scripting Example | Main | IRC Bot Tutorial »

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

Technorati Tags:

Posted by rafael.sobek at 10:35 PM in Java

 

[Trackback URL for this entry]

Your comment:

(not displayed)
 
 
 

Live Comment Preview:

 
« January »
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31