SVG to JPEG : SVG « XML « Java






SVG to JPEG


import java.io.*;
import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;

public class SVGDOC2JPEG {

  public static void main(String[] args) throws Exception {

    JPEGTranscoder transcoder = new JPEGTranscoder();

    transcoder.addTranscodingHint(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
        "org.apache.crimson.parser.XMLReaderImpl");
    transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
        new Float(1.0));

    TranscoderInput input = new TranscoderInput(new FileInputStream("rectangles.svg"));
    OutputStream ostream = new FileOutputStream("out.jpg");
    TranscoderOutput output = new TranscoderOutput(ostream);

    transcoder.transcode(input, output);
    ostream.close();
    System.exit(0);
  }
}
           
       








Related examples in the same category

1.SVG Graphics DDemo
2.SVG Canvas Demo