Brecht Yperman wrote:
i'm having some problems trying to create JPEG/TIFF/PNG-images from an
svggraphics2d element in memory.
I used to write an svg file to the file system and then read it in
again to transcode it, but that's a bit messy.
Can anyone help me?
Well the problem below is probably that your sink writer
and your source reader need to be in different threads otherwise
the write blocks waiting for someone to read when the buffers
fill up.
However I think you would be _much_ better off passing
the DOM that the svgGenerator builds directly to the Transcoder
(TranscoderInput will take a document). To get the
document you want to do something like:
// The following populates the document root with the
// generated SVG content.
Element root = document.getDocumentElement();
svgGenerator.getRoot(root);
private static void transcode(Visualisation vis, File file, ImageTranscoder
t, Dimension dim) throws IOException {
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
ctx.setComment("Generated by Trs-visualisation");
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
svgGenerator.setSVGCanvasSize(dim);
vis.render(svgGenerator, new Double(dim.getWidth()).intValue(), new
Double(dim.getHeight()).intValue(), null);
PipedReader sink = new PipedReader();
PipedWriter source = new PipedWriter(sink);
svgGenerator.stream(source);
TranscoderInput input = new TranscoderInput(sink);
OutputStream ostream = null;
try {
ostream = new FileOutputStream(file);
} catch (FileNotFoundException e3) {
logger.error(e3);
}
TranscoderOutput output = new TranscoderOutput(ostream);
try {
t.transcode(input, output);
} catch (TranscoderException e1) {
logger.error(e1);
}
ostream.flush();
ostream.close();
new File("temp.svg").delete();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]