Rob wrote:
Hi,

Im trying to write a little app that uses the rasterizer to convert an
SVG to a PNG. Obviously this is exactly what batik-rasterizer.jar
does, however I want to be able to write a servlet and import
org.apache.batik.apps.rasterizer.*, and then be able to rasterize the
file on the fly.

You can just use the rasterizer class directly. That way you have more direct control.


Here is a code sample from a servlet rasterizing SVG to PNG (http://cvs.berlios.de/cgi-bin/viewcvs.cgi/digilib/servlet/src/digilib/servlet/Raster.java?rev=HEAD&content-type=text/vnd.viewcvs-markup):

// read the document
SVGDocument doc =
        docFactory.createSVGDocument(
                fileToLoad.getFile().toURI().toString());
// extract the SVG root
SVGSVGElement svgroot = doc.getRootElement();
// get document width and height
float imgWidth = svgroot.getWidth().getBaseVal().getValue();
float imgHeight = svgroot.getHeight().getBaseVal().getValue();

/*
 * set up the transcoder
 */

// create a PNG transcoder
PNGTranscoder transcoder = new PNGTranscoder();
// create the transcoder input
//InputStream is = new FileInputStream(fileToLoad.getFile());
TranscoderInput input = new TranscoderInput(doc);
logger.info("Loading: " + fileToLoad.getFile());
// create the transcoder output
TranscoderOutput output =
        new TranscoderOutput(response.getOutputStream());
// output is image/png
response.setContentType("image/png");

// area of interest
Rectangle2D aoi =
new Rectangle2D.Double(
                paramWX * imgWidth,
                paramWY * imgHeight,
                paramWW * imgWidth,
                paramWH * imgHeight);
transcoder.addTranscodingHint(PNGTranscoder.KEY_AOI, aoi);

// destination image dimensions
if (paramDW > 0) {
        transcoder.addTranscodingHint(
                PNGTranscoder.KEY_WIDTH,
                new Float(paramDW));
}
if (paramDH > 0) {
        transcoder.addTranscodingHint(
                PNGTranscoder.KEY_HEIGHT,
                new Float(paramDH));
}

/*
 * transcode
 */

transcoder.transcode(input, output);

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to