xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: Adding JPG to SVG Document
Date Thu, 19 Apr 2007 10:31:16 GMT
Hi Brian, Archie,

archie.cobbs@gmail.com wrote on 04/16/2007 10:23:44 AM:

> On 4/16/07, Brian Corrigan <brian.corrigan@ammeon.com> wrote:
> > I'm looking to add a JPG image to an SVG document but want to do it 
with
> > out manually adding an xml element. 

   I think you want to look at using 'createElementNS' and
setAttributeNS.  In particular you need to make sure that you
remember to use the XLink namespace for the xlink:href attribute:

        Element img = doc.createElementNS("http://www.w3.org/2000/svg", 
"image");
        img.setAttributeNS(NULL, "width", "50");
        img.setAttributeNS(NULL, "height", "50");
        [...]
        img.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", 
                           "http://www.example.com/foobar.jpg");


> > Was looking at the ImageNode and think its what I'm looking for but 
> > I have know idea how I would go about using it properly. The only 
> > examples I can find are of exporting an SVG Doc to a jpg/png/etc.

   Yah, unless you are doing something very special you don't want to
go mucking around in the GVT tree.  Stick to using the DOM to update
the display.

    Also please take care to make all modifications to the Document in
the UpdateManager's RunnableQueue (see FAQ for details).

> Here's an example of the general idea...

   This would require 'manually adding an xml element'.

>   <image transform="translate(-25, -25)" width="50" height="50"
>       xmlns:xlink="http://www.w3.org/1999/xlink"
>       xlink:href="http://www.example.com/foobar.jpg"
>       preserveAspectRatio="xMidYMid meet"/>
> 
> I usually center the imported image with a translation as shown.

   For many use cases this is useful.  However I might mention
that you can also just set 'x="-25"' and 'y="-25"' for a similar
effect.


---------------------------------------------------------------------
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