[JAI-IMAGEIO] I need a way to decode an image file directly into a byte or integer
array...

Posted by [1] on May 12, 2008 at 12:23 AM PDT

I think there is a hole in the greater Java API for working with images.

Images and BufferedImages are great if all you want to do is download
an image file and put it on the screen. They are really good at that.

But if someone (like myself) needs to work at a lower level -- at the pixel
level to prepare and synthesize pixels for display, the existing API's
are way too complicated.

There is no way to read an image file -- jpg, tif, png, whatever -- and
simply decode that image file into a byte or integer array. You always
have to ask for an image of one sort or another to be created.

And that is not a straight forward procedure either. If you use the Toolkit
to make your image, you have to make a MediaTracker to wait for the image
to be made somewhere deep in the JVM.

Then, if you want to manipulate the pixels of the image directly either to change
the color or position of a particular pixel or to generate a new set of pixels,
you have to either ask the image for the pixel or use a PixelGrabber to ask
the image for it's pixels in either byte array or integer array form.

If you use a PixelGrabber, again you have to wait for an ImageProducer to
deliver the pixels in the array of your choice. And that process has
to be carefully minded to make sure it completes.

It would be so much simpler if I could just decode an image file directly
into a byte or integer array.

I'm starting a new project where I will be rendering huge panoramic images
sometimes as big as 50,000x25,000 pixels or even bigger. To do that, I will
be downloading tiles from the panorama as needed on demand. The image will be made
into a manageable set of tiles by other tools. There may even be a set
of tiles at different resolutions for the same panorama.

So for each tile I have to download the image file, make an image and
watch over that process with a MediaTracker and after the Image is made,
make a PixelGraber to grab the pixels and watch over that process then
when I have (in my code) integer array -- I throw all that stuff away
(flush the image resources etc.) and do the whole thing over again for the
next tile.

Maybe ImageIO Tools has a way to do that but now that's a separate download
and install and until the next generation plugin -- which will simplify
silent installs of extra packages -- is widely deployed , not an
option.

I don't know of a way to simply decode an image file into a byte or integer
array. I hope that there really is a way and I'm just not aware of it. I
don't mind being dumb. I'm dumb a lot. So if anyone knows a way to
decode an image file directly into a byte or integer array, please
tell me how to do it.