xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cameron McCormack <...@mcc.id.au>
Subject Re: Manipulation of existing svg document
Date Wed, 28 May 2008 08:07:01 GMT
Hi Lars.

Lars Eirik Rønning:
> I have an existing svg document where some of the nodes act as placeholders.
> Basically these placeholders will be replaces with base64 encoded images.
> 1:Are there any convenience methods for adding images to an svg document or
> do i have to manually base64encode the stream and add all attributes such as
> widht and height?
> I have already added an element using the SVGConstant for Images, but to mee
> this still looks like its more or less the same as using any other
> xmldocument.

If you have, say, a BufferedImage and you want to convert it into a
data: URI, you can do the following:

  BufferedImage img = …;

  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  Base64EncoderStream b64 = new Base64EncoderStream(bytes);
  PNGImageEncoder enc = new PNGImageEncoder(b64, null);

  String uri = "data:image/png;base64," + bytes.toString();
Then you can construct a new <image> element and set its xlink:href=""
attribute to that URI.  This is essentially what the SVGGraphics2D class
does when it gets a drawImage() call.

> If there are any guides or tutorials to using dom for handling images i am
> very happy to receive some pointers..
> 2:One of my concerns is that i probably have to add the transformation
> matrix myself. I was hoping that there could be some convenience methods
> which would help me on my way for doing these types of operations.
> Is the transformation matrix necessary in order for the image (or any
> element) to be visible in a svg document?

I’m not quite sure what you want to achieve, so I don’t know whether you
need to set a transform='" on the <image> elements or not.

Cameron McCormack ≝ http://mcc.id.au/

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

View raw message