Skip to main content

SubsampleAverage -> getAsBufferedImage = Coordinate out of bounds Exception

3 replies [Last post]
mwadhera
Offline
Joined: 2008-11-07
Points: 0

Hi, i'm currently using JAI 1.1.3 to resize PNG's with the "SubsampleAverage" operation, as this seems to be yielding the best quality for many people using JAI.

The operation itself runs as expected but calling getAsBufferedImage() on the RenderedOp returned from JAI.create() raises a "Coordinate out of bounds" exception.

Here is a link to my code: http://pastie.org/309757

And heres the exception w/stack trace: http://pastie.org/309768

Its also worth noting that if I change the operation to "scale", no exception is raised.

Am I missing something?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mart1n
Offline
Joined: 2009-06-09
Points: 0

Could you solve this issue? I have the same problem, however only under Mac OS and not under Windows.

agirbal
Offline
Joined: 2009-05-04
Points: 0

still have same issue under Mac, I guess issue still not resolved.
If you have any workaround let me know.
I tried several ways of resizing but settled for subsample since it's both fast and of good quality..
WARNING: Coordinate out of bounds!
java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getByteData(ByteInterleavedRaster.java:439)
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:351)
at java.awt.image.BufferedImage.getData(BufferedImage.java:1421)
at javax.media.jai.RenderedImageAdapter.getData(RenderedImageAdapter.java:166)
at javax.media.jai.GeometricOpImage.computeTile(GeometricOpImage.java:676)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:912)
at javax.media.jai.OpImage.getTile(OpImage.java:1139)
at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2356)
at javax.media.jai.RenderedOp.copyData(RenderedOp.java:2310)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2538)

astro0
Offline
Joined: 2011-07-14
Points: 0

I managed to solve the issue by changing how I loaded the source image.

Previously I was using something like this:

BufferedImage image = ImageIO.read( imageFile );
ParameterBlock parameterBlock = new ParameterBlock();
double scale = (double)width / (double)originalWidth;;
parameterBlock.addSource(image);
parameterBlock.add(scale);
parameterBlock.add(scale);
parameterBlock.add(0);
parameterBlock.add(0);
RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
RenderedOp resized = JAI.create("SubsampleAverage", parameterBlock, renderingHints);
return resized.getAsBufferedImage();

That kept giving Coordinate out of bounds errors.

Changed it to the following made it start working:
PlanarImage image = JAI.create("fileload", imageFile.getAbsolutePath() );