xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas.Ha...@blum.com
Subject xlink:href
Date Wed, 14 Mar 2007 09:57:00 GMT
Hello,

I have a problem displaying SVGDocuments with an embedded image in a 
JSVGCanvas.

I have the following code which creates the SVGDocument with an image 
embbed in it.

DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
SVGDocument document = (SVGDocument) 
impl.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);
Element svgRoot = document.getDocumentElement();

BufferedImage image = ImageIO.read(file);
ImageProcessor ip = new ImageProcessor(image, "jpeg");

svgRoot.setAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + 
image.getWidth() + " " + image.getHeight());
svgRoot.setAttributeNS(null, "width", String.valueOf(image.getWidth()));
svgRoot.setAttributeNS(null, "height", String.valueOf(image.getHeight()));
Element imageElement = 
document.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "image");
imageElement.setAttributeNS(null, "x", "0");
imageElement.setAttributeNS(null, "y", "0");
imageElement.setAttributeNS(null, "width", 
String.valueOf(image.getWidth()) + "px");
imageElement.setAttributeNS(null, "height", 
String.valueOf(image.getHeight()) + "px");
imageElement.setAttributeNS(null, "xlink:href", "data:image/jpg;base64," + 
Base64.encode(ip.getImageAsByteArray()));
svgRoot.appendChild(imageElement);

The problem is that if I try to load this document in an JSVGCanvas (with 
the setDocument() method) I get and error message and the following 
exception.

org.apache.batik.bridge.BridgeException: null:-1
The attribute "xlink:href" of the element <image> is required
        at 
org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(Unknown 
Source)
        at 
org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(Unknown 
Source)
        at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown 
Source)
        at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown 
Source)
        at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
        at org.apache.batik.swing.svg.GVTTreeBuilder.run(Unknown Source)

The funny thing is that if I fist save the document to a file and create a 
document with the SAXSVGDocumentFactory the file works perfectly. Am I 
missing something?

kind regards
Thomas
Mime
View raw message