Hi Alexander,

Alexander Shyrokov <shyro...@stsci.edu> wrote on 04/28/2011 09:14:04 AM:

> I have a method that generates an array of bytes, which can be 
> represented as a two dimensional image. I would like to show this image 
> as a background image in batik. I do not want to save the array to disk 
> (as image) and then load it into batik. Instead I would like to provide 
> the array to the batik. I though that using ParsedURLData can help me, 
> but I can not figure out how to make it work. Any suggestions?

        So ParsedURL could help if your image data was in JPEG or PNG 
format, but I suspect
it isn't since you mention it's 2D.  Assuming your bytes are RGB color 
values for the pixels in the
image I would suggest figuring out how to wrap that data into the 
java.awt.image.BufferedImage.

        Then you could build a o.a.batik.gvt.RasterImageNode that you 
insert into the GVT tree.
You can take a BufferedImage and set it on the RasterImageNode.  You might 
look at the 
o.a.batik.ext.awt.image.codec.jpeg.JPEGRegistryEntry in particular the 
lines:

                cr = GraphicsUtil.wrap(image);
                        filt = new RedRable(cr);

        Which wrap a standard buffered Image such that it's suitable to 
set on a RasterImageNode
(it allows it to scale properly).

        Personally I'd probably encode the image as a JPEG or PNG and
set it as a 'data' URL since that would avoid the direct mucking with
the GVT tree (generally problematic).  The other option is if it will
always be the 'background' would be to modify the Canvas to use your
image as the background fill.

Reply via email to