You may be accessing the document before the gvt builder is complete... try
adding a listener and then loading the doc. Begin your work when the
listener is called...
canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
@Override
public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
// do stuff here
}
});
On Wed, Sep 12, 2012 at 6:45 PM, Thomas DeWeese
<[email protected]> wrote:
Hi Ali,
> Hmm, I think we misunderstood. You have an SVG document and you
> can view most of it in the JSVGCanvas but the embedded png's don't show up.
> In that case I think you need to send a sample document that shows the
> problem for you because they should just show up (there are examples
> included in batik like 'sample/tests/spec/structure/dataProtocol.svg'.
>
> Thomas
>
> On Sep 12, 2012, at 12:11 PM, ali can wrote:
>
> > Please excuse my ignorance but I really cannot get a grip of this. Here
> is my
> > code, I can see svg, but no embed image. What is wrong?
> > Thanks
> >
> > canvas = new JSVGCanvas();
> > getContentPane().add(canvas);
> >
> > userAgent = new UserAgentAdapter();
> > ctx = new BridgeContext(userAgent);
> > builder = new GVTBuilder();
> > try {
> > // Parse the barChart.svg file into a Document.
> > String parser = XMLResourceDescriptor.getXMLParserClassName();
> > SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
> > URL url = new URL(getCodeBase(), "embedData.svg");
> > doc = f.createDocument(url.toString());
> >
> > svg = doc.getDocumentElement();
> >
> >
> > NodeList l =
> > svg.getElementsByTagName("image") ;
> > for (int i = 0; i < l.getLength(); i++)
> > {
> > Element n = (Element)l.item(i) ;
> > String image =
> > n.getAttributeNS(XMLConstants.XLINK_NAMESPACE_URI,
> > "href");
> > String t = n.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE);
> > int width = Integer.parseInt(t);
> > int height = Integer.parseInt(n.getAttributeNS(null,
> > SVG_HEIGHT_ATTRIBUTE));
> > String id = "image" + Integer.toString(i);
> >
> > // Create and initialize the new image element
> > Element imageElement =
> > doc.createElementNS(SVG_NAMESPACE_URI,
> > SVG_IMAGE_TAG);
> > imageElement.setAttributeNS(null,
> > XMLConstants.XML_ID_ATTRIBUTE,
> > id);
> > imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE,
> > Integer.toString(width));
> > imageElement.setAttributeNS(null, SVG_HEIGHT_ATTRIBUTE,
> > Integer.toString(height));
> >
> > imageElement.setAttributeNS(XMLConstants.XLINK_NAMESPACE_URI,
> > XMLConstants.XLINK_HREF_QNAME,
> > "data::image/PNG;base64," +
> > base64Encode(image.getBytes()));
> > doc.appendChild(imageElement);
> > svg.removeChild(n);
> > }
> > } catch (Exception ex) {
> > }
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> http://batik.2283329.n4.nabble.com/How-to-render-embedded-png-tp4655236p4655244.html
> > Sent from the Batik - Users mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > 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]
>
>