I tried creating images from BLOBs in Northwind database that Microsoft
provides as a sample for its SQL Server 2000. These BLOBs contain BMP
images, but for some weird reason all byte arrays have a 78-byte header
prepended to the contents, so in order to produce the displayable image the
header must stripped off first.
So, I tried this code in JAI:
// Get byte[] data from the BLOB, then do the following:
ByteArraySeekableStream stream = new ByteArraySeekableStream(data, 78,
data.length - 78);
PlanarImage source = JAI.create("stream", stream);
WritableRaster raster = source.copyData(); <== exception thrown here
ColorModel cm = source.getColorModel();
BufferedImage image = new BufferedImage(cm, raster, false, (Hashtable)
null);
It did not work. Then I changed it to this:
// Get byte[] data from the BLOB, then remove the header:
byte[] newData = new byte[data.length - 78];
for (int i = 78; i < newData.length; i++)
newData[i - 78] = data[i]; // make new byte array, stripping off
first 78 bytes
ByteArraySeekableStream stream = new ByteArraySeekableStream(newData);
PlanarImage source = JAI.create("stream", stream);
WritableRaster raster = source.copyData(); <== no exception anymore
BufferedImage image = new BufferedImage(cm, raster, false, (Hashtable)
null);
Everything worked.
So, it appears to me that ByteArraySeekableStream does not handle the offset
properly in its constructor. I haven't found any bug reports or a discussion
of this matter on Forums.
Did anyone run into something similar? If not, I will file a bug report with
Sun.
TIA for any enlightenment.
Alex Molochnikov
Gestalt Corporation
www.gestalt.com
ak - 06 Feb 2004 09:40 GMT
Hi Alex,
> ByteArraySeekableStream stream = new ByteArraySeekableStream(data, 78,
> data.length - 78);
[quoted text clipped - 3 lines]
> BufferedImage image = new BufferedImage(cm, raster, false, (Hashtable)
> null);
this question you should ask here:
http://swjscmail1.sun.com/archives/jai-interest.html.
Did you tryed ImageroReader? It has neat features like unified IO
(RandomAccess for many things - InputStream, byte arrays, http)
and it is quick and consumes not much memory.
Regards
Andrei
--
____________
http://reader.imagero.com the best java image reader.
Alex Molochnikov - 06 Feb 2004 18:13 GMT
Thank you, Andrei.
I will try the JAI mailing list.
As for Imagero - it is most likely a nice gadget, but our app is a
commercial product for sale in the open market, and we cannot burden it with
third-party licensing fees.
Regards,
Alex.
> Hi Alex,
>
[quoted text clipped - 22 lines]
>
> http://reader.imagero.com the best java image reader.
ak - 06 Feb 2004 18:19 GMT
> ByteArraySeekableStream stream = new ByteArraySeekableStream(data, 78,
> data.length - 78);
[quoted text clipped - 3 lines]
> BufferedImage image = new BufferedImage(cm, raster, false, (Hashtable)
> null);
what I can't understand is why you first create PlanarImage and after
convert it to BufferedImage.
Use ImageIO and read direct as BufferedImage.
____________
http://reader.imagero.com the best java image reader.
Andrew Thompson - 06 Feb 2004 19:06 GMT
...
> http://reader.imagero.com the best java image reader.
Have you been updating the site ak?
It looks different to when I saw it recently.
(If I remember right)
ak - 06 Feb 2004 21:49 GMT
> Have you been updating the site ak?
> It looks different to when I saw it recently.
> (If I remember right)
which site - reader or www?
reader site is 100% ok (I hope)
____________
http://reader.imagero.com the best java image reader.
Andrew Thompson - 07 Feb 2004 06:09 GMT
>> Have you been updating the site ak?
>> It looks different to when I saw it recently.
>> (If I remember right)
>
> which site - reader or www?
reader..
> reader site is 100% ok (I hope)
Yep. It just seemed to look
'slicker' (shrugs vaguely) than
when I had seen it recently.
ak - 07 Feb 2004 11:14 GMT
> > reader site is 100% ok (I hope)
>
> Yep. It just seemed to look
> 'slicker' (shrugs vaguely) than
> when I had seen it recently.
may be jars TopRated logo is the problem?
that was the only significant change last time.
____________
http://reader.imagero.com the best java image reader.
Andrew Thompson - 07 Feb 2004 11:30 GMT
>>> reader site is 100% ok (I hope)
>>
[quoted text clipped - 4 lines]
> may be jars TopRated logo is the problem?
> that was the only significant change last time.
It is not a problem, the page looks good.
[ ..but I have realised I really should not be
discussing your site in the forum... ;-) ]
Alexandr Molochnikov - 07 Feb 2004 00:04 GMT
> what I can't understand is why you first create PlanarImage and after
> convert it to BufferedImage.
> Use ImageIO and read direct as BufferedImage.
I have to use JAI to support the widest possible range of image formats. The
approach you suggest does not work with formats other tha GIF, JPEG and
PNG. E.g. for BMP images the BufferedImage returned from ImageIO is null.
PlanarImage etc. is how JAI creates images.
Regards,
Alex.
Marco Schmidt - 07 Feb 2004 00:43 GMT
Alexandr Molochnikov:
>I have to use JAI to support the widest possible range of image formats. The
>approach you suggest does not work with formats other tha GIF, JPEG and
>PNG. E.g. for BMP images the BufferedImage returned from ImageIO is null.
You can download plugins for ImageIO from
<http://java.sun.com/products/java-media/jai/downloads/download-iio.html>.
Quote:
JAI Image I/O Tools provides reader, writer, and stream plug-ins for
the Java Image I/O Framework and Image I/O-based read and write
operations for Java Advanced Imaging. Reader-writer plug-ins are
supplied for the BMP, JPEG, JPEG 2000, PNG, PNM, Raw, TIFF, and WBMP
image formats. The supplied streams and associated service providers
use the New I/O APIs.
Java 1.5 (now available as a beta version) comes with built-in BMP
support:
<http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/package-summary.html#packa
ge_description>.
Regards,
Marco

Signature
Please reply in the newsgroup, not by email!
Java programming tips: http://jiu.sourceforge.net/javatips.html
Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html