You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Denis Weerasiri <dd...@gmail.com> on 2008/11/11 10:29:46 UTC

Embed a png in svg using Batik

I'm completely new to Batik. I need to know how to refer to an png file
through an svg file using Batik.
Please help me on this case.

Re: Embed a png in svg using Batik

Posted by Denis Weerasiri <dd...@gmail.com>.
I think my problem is solved. I can use

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.w3c.dom.DOMImplementation;

and manage my program.
Thank You.

Re: Embed a png in svg using Batik

Posted by Denis Weerasiri <dd...@gmail.com>.
On Tue, Nov 11, 2008 at 4:40 PM, <th...@kodak.com> wrote:

>
> Hi Denis,
>
> "Denis Weerasiri" <dd...@gmail.com> wrote on 11/11/2008 05:47:33 AM:
>
> > I use
> > import org.apache.batik.svggen.SVGGraphics2D;
> > import org.apache.batik.swing.JSVGCanvas;
>
> > above set of classes for my program. I have some data from a DB and
> > based on those data I need to generate a flow diagram using SVG.
> > For some components in that flow diagram I need to display png images.
>
>     So you are drawing the diagram using Java
> Graphics2D and displaying that in the Canvas?
>
>     You can always use Java2D to fetch an decode the PNG image
> using java.awt.Toolkit.createImage(URL) (make sure the image
> is fully loaded before you draw it to the SVGGraphics2D).
>
> > import org.w3c.dom.Element;
> > import org.w3c.dom.svg.SVGDocument;
>
>     Alternately if you are already manipulating the SVG
> document after SVGGraphics2D has generated most of it you
> can use Document.createElementNS to create an SVG image element
> and the Element.setAttributeNS to set the xlink:href attribute
> (to either a URL for the PNG, or base64 data - which you
> can get from the Batik.util.Base64EncoderStream).  I suspect
> just drawing the Image to the Graphics2D will be your
> best bet.
>
> > import org.apache.batik.dom.svg.SVGDOMImplementation;
> > import org.w3c.dom.DOMImplementation;
> >
>

Re: Embed a png in svg using Batik

Posted by th...@kodak.com.
Hi Denis,

"Denis Weerasiri" <dd...@gmail.com> wrote on 11/11/2008 05:47:33 AM:

> I use
> import org.apache.batik.svggen.SVGGraphics2D;
> import org.apache.batik.swing.JSVGCanvas;

> above set of classes for my program. I have some data from a DB and 
> based on those data I need to generate a flow diagram using SVG. 
> For some components in that flow diagram I need to display png images. 

    So you are drawing the diagram using Java 
Graphics2D and displaying that in the Canvas?

    You can always use Java2D to fetch an decode the PNG image
using java.awt.Toolkit.createImage(URL) (make sure the image
is fully loaded before you draw it to the SVGGraphics2D).

> import org.w3c.dom.Element;
> import org.w3c.dom.svg.SVGDocument;

    Alternately if you are already manipulating the SVG
document after SVGGraphics2D has generated most of it you
can use Document.createElementNS to create an SVG image element
and the Element.setAttributeNS to set the xlink:href attribute
(to either a URL for the PNG, or base64 data - which you
can get from the Batik.util.Base64EncoderStream).  I suspect
just drawing the Image to the Graphics2D will be your
best bet.

> import org.apache.batik.dom.svg.SVGDOMImplementation;
> import org.w3c.dom.DOMImplementation;
> 

Re: Embed a png in svg using Batik

Posted by Denis Weerasiri <dd...@gmail.com>.
Thank you again you support.
I use

import org.apache.batik.dom.svg.SVGDOMImplementation;import
org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.swing.JSVGCanvas;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;

above set of classes for my program. I have some data from a DB and based on
those data I need to generate a flow diagram using SVG.
For some components in that flow diagram I need to display png images.

Re: Embed a png in svg using Batik

Posted by th...@kodak.com.
Hi Denis,

"Denis Weerasiri" <dd...@gmail.com> wrote on 11/11/2008 05:01:58 AM:

> Thank you for the attention. But I need to use Batik to specify 
> those parameters in the <image> tag 

   Batik is a large package without knowing how or what you
are using from Batik I don't know what you mean by using Batik
to specify the parameters.

   Can you give a little more background on what you are doing
and how you are using Batik?


Re: Embed a png in svg using Batik

Posted by Denis Weerasiri <dd...@gmail.com>.
Thank you for the attention. But I need to use Batik to specify those
parameters in the <image> tag

Re: Embed a png in svg using Batik

Posted by Denis Weerasiri <dd...@gmail.com>.
Thank you for the attention. But I need to use Batik to specify those
parameters.
Please help me on this.

Re: Embed a png in svg using Batik

Posted by Denis Weerasiri <dd...@gmail.com>.
Thank you for the attention. But I need to use Batik an specify those
parameters.
Please help me on this.

Re: Embed a png in svg using Batik

Posted by Lars Eirik Rønning <la...@gmail.com>.
or you could remove the base64 aspect of it and use
xlink:href="file:///mypath/myfile.png"

On Tue, Nov 11, 2008 at 10:50 AM, massimo citterio <ci...@sinapto.net> wrote:

> On Tue, 2008-11-11 at 14:59 +0530, Denis Weerasiri wrote:
> > I'm completely new to Batik. I need to know how to refer to an png
> > file through an svg file using Batik.
> > Please help me on this case.
>
> try this
>
> <image
>   width="46"
>   height="88"
>  xlink:href="data:image/png;base64,_____put here the base64 encoded
> image____" />
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>

Re: Embed a png in svg using Batik

Posted by massimo citterio <ci...@sinapto.net>.
On Tue, 2008-11-11 at 14:59 +0530, Denis Weerasiri wrote:
> I'm completely new to Batik. I need to know how to refer to an png
> file through an svg file using Batik.
> Please help me on this case.

try this

<image
   width="46"
   height="88"
 xlink:href="data:image/png;base64,_____put here the base64 encoded
image____" />



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