xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: preserve alpha channel in PNG
Date Wed, 02 Apr 2008 10:43:41 GMT
Hi Jeff,

Jeff Abernathy <jeff.abernathy@asolutions.com> wrote on 03/27/2008 04:25:08

> I'm trying to embed PNG images using base64 data, but when I do, I
> lose the alpha channel. This is how I'm creating the image element:
> new

> The PNGs are showing up on the canvas, but they have lost their
> transparent pixels. Is there a way to embed PNGs and keep the alpha
> channel without referencing the image's path on the file system?

   Batik certainly supports transparent pixels in embedded PNG images.
My guess is that the ImageIO reader is dropping the transparent pixels.
However the above code is doing a lot more than it really needs to.
To embed the PNG as Base64 you should be able to read the PNG file data
(Just open an InputStream to the file) and send the data through our
Base64EncoderStream (probably to a ByteArrayOutputStream).  Then you
can set the Base64 data as the link:href (with the "data:image/png;base64,"
stuff at the front).
View raw message