xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas DeWeese <thomas.dewe...@gmail.com>
Subject Re: How to render embedded png?
Date Wed, 12 Sep 2012 22:45:50 GMT
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: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message