Skip to main content

PlanarImage.getImage - ArrayIndexOutOfBoundsException

2 replies [Last post]
skannan21
Offline
Joined: 2010-05-29

HI

We stored the image in DB2 Database in a Blob column and below code is to retrieve the same and trying to scale the image. But we are getting ArrayIndexOutOfBoundException on some Images(Not on all the images). can you please help. Codes are below.

ImageResult is the ResultSet from the DB and coulmn index 2 has the Image. Rest of the codes given below.

byte[] thumbnailRow = imageResult.getBytes(2);
ByteArraySeekableStream bytearrayseekablestream = new ByteArraySeekableStream(thumbnailRow);
String as[] = ImageCodec.getDecoderNames(bytearrayseekablestream);
ImageDecoder imagedecoder = ImageCodec.createImageDecoder(as[0], bytearrayseekablestream, null);
java.awt.image.RenderedImage renderedimage = imagedecoder.decodeAsRenderedImage();
PlanarImage plnrmessage = PlanarImage.wrapRenderedImage(renderedimage);
BufferedImage buffer = plnrmessage.getAsBufferedImage(); // Db2 Connect.Java Line Number 109.
//Exception occured on the above line.
Image img = buffer.getScaledInstance(118, -1, Image.SCALE_FAST);
thumbnailIcon = new ImageIcon(img);

Exception:
==================================
java.lang.ArrayIndexOutOfBoundsException: 1157
at com.sun.media.jai.codecimpl.TIFFFaxDecoder.nextLesserThan8Bits(TIFFFaxDecoder.java:1484)
at com.sun.media.jai.codecimpl.TIFFFaxDecoder.decodeT6(TIFFFaxDecoder.java:955)
at com.sun.media.jai.codecimpl.TIFFImage.getTile(TIFFImage.java:1075)
at com.sun.media.jai.codecimpl.SimpleRenderedImage.copyData(SimpleRenderedImage.java:552)
at javax.media.jai.RenderedImageAdapter.copyData(RenderedImageAdapter.java:163)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2525)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at cvs.test.Db2Connect.main(Db2Connect.java:109)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
skannan21
Offline
Joined: 2010-05-29

Hi

Can anyone please help me on my Query?

Thanks.
Kannan.

skannan21
Offline
Joined: 2010-05-29

Hi

I am getting one more error on the same code. Please help and advise on the same. Thanks.

java.lang.RuntimeException: Invalid code encountered while decoding 2D group 4 compressed data.
at com.sun.media.jai.codecimpl.TIFFFaxDecoder.decodeT6(TIFFFaxDecoder.java:1096)
at com.sun.media.jai.codecimpl.TIFFImage.getTile(TIFFImage.java:1075)
at com.sun.media.jai.codecimpl.SimpleRenderedImage.copyData(SimpleRenderedImage.java:552)
at javax.media.jai.RenderedImageAdapter.copyData(RenderedImageAdapter.java:163)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2525)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at cvs.test.Db2Connect.getThumbnailDb2Connect.java:725)