>>>>> "RG" == Robert Gash <[EMAIL PROTECTED]> writes:
RG> I am using the SVG generator to create a new SVG by drawing on a
RG> Graphics2D object. Once updates are complete, I need to rasterize
RG> this image to a PNG. When I do so, the PNGTranscoder (and
RG> JPEGTranscoder) continuously produce appropriately sized, but
RG> blank images (IE- a big image full of background color).
RG> I have saved the SVG that I am attemting to rasterize, and Adobe's
RG> SVG viewer displays is properly. What might I be missing that
RG> could cause problems like this?
I would at first blush guess a namespace issue of some kind. If
your root element is not an 'svg:svg' so to say then the rasterizer
will ignore the whole document. This is a common problem because in a
sense the rules applied when parsing are different from the DOM rules
- so writing the file out and re-reading it often 'fixes' the file.
That all said I'm not sure where the problem would occur since it
is mostly Batik code that is creating elements. It would probably be
worth your while to print the namespaceURI and tag name for svgRoot
and the direct children of svgRoot.
Also width and height should not be in the SVG namespace they
should be in the 'default' namespace (just use setAttribute or
setAttributeNS(null, ...) - I'll leave it to others to decide which is
truly correct but both work in Batik).
RG> Here is the code:
RG> DOMImplementation domImpl =
RG> SVGDOMImplementation.getDOMImplementation(); Document doc =
RG> domImpl.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI,
RG> "svg", null);
RG> SVGGraphics2D svgGenerator = new SVGGraphics2D(doc); Element
RG> svgRoot = doc.getDocumentElement(); cr.drawScope(svgGenerator,
RG> 400, 400); svgGenerator.getRoot(svgRoot);
RG> svgRoot.setAttributeNS(SVGDOMImplementation.SVG_NAMESPACE_URI,
RG> "width", "400");
RG> svgRoot.setAttributeNS(SVGDOMImplementation.SVG_NAMESPACE_URI,
RG> "height", "400");
RG> // prepare the input and output for the transcoding process
RG> TranscoderInput ti = new TranscoderInput(doc); OutputStream
RG> outFile = new FileOutputStream("test/radar.png"); TranscoderOutput
RG> to = new TranscoderOutput(outFile);
RG> // prep the PNG transcoder for output Transcoder t = new
RG> PNGTranscoder();
RG>
t.addTranscodingHint(org.apache.batik.transcoder.image.ImageTranscoder.KEY_BACKGROUND_COLOR,
RG> Color.WHITE);
RG> t.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, new
RG> Float(400));
RG> t.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, new
RG> Float(400));
RG> Writer out = new FileWriter("test/radar.xml"); XMLSerializer xs =
RG> new XMLSerializer(out, new OutputFormat(doc)); xs.serialize(doc);
RG> // transcode t.transcode(ti, to);
RG> outFile.flush(); outFile.close();
RG> -- Robert Gash, [EMAIL PROTECTED] (Web) http://gashalot.com/
RG> (PGP) http://gashalot.com/pgpkeys.txt
RG> ---------------------------------------------------------------------
RG> To unsubscribe, e-mail: [EMAIL PROTECTED] For
RG> additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]