xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas DeWeese <Thomas.DeWe...@Kodak.com>
Subject Re: Add IMAGE from BufferedImage into a loaded SVG Document
Date Mon, 14 Feb 2005 15:59:18 GMT
Andres Toussaint wrote:

> My Main question is: How is the best way to add this image into my document?

     Encode it as a PNG and include it in the xlink:href using
the data protocol.  This is what the code below does (very
indirectly).

     The code to do this more directly (take from
batik.svggen.ImageHandlerBase64Encoder) is something like:

     public static final String DATA_PROTOCOL_PNG_PREFIX =
	"data:image/png;base64,";

         ByteArrayOutputStream os = new ByteArrayOutputStream();
         Base64EncoderStream b64Encoder = new Base64EncoderStream(os);

         ImageEncoder encoder = new PNGImageEncoder(b64Encoder, null);
         encoder.encode(buf);

         // Close the b64 encoder stream (terminates b64 streams).
         b64Encoder.close();

         imageElement.setAttributeNS(XLINK_NAMESPACE_URI,
                                     ATTR_XLINK_HREF,
                                     DATA_PROTOCOL_PNG_PREFIX +
                                     os.toString());

> Also, will doing this approach create a Embedded Image in my SVG? Or how 
> is the reference to the Image handled? What format of image will be 
> embedded (PNG, JPG,...)?

    The above will embed the image in the SVG.

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


Mime
View raw message