Skip to main content

BufferedImage Created by ImageIO not compatible with AffineTransformOp

1 reply [Last post]
ifoster
Offline
Joined: 2006-03-28

I am having some difficulties with BufferedImages created by the ImageIO class, they are causing the following excpetion to be thrown in the AffineTransformOp class;

Exception in thread "AWT-EventQueue-0" java.awt.image.ImagingOpException: Unable to transform src image
at java.awt.image.AffineTransformOp.filter(AffineTransformOp.java:267)
at sun.java2d.pipe.DrawImage.renderImageXform(DrawImage.java:405)
at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:248)
at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:194)
at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:947)
at sun.java2d.pipe.ValidatePipe.transformImage(ValidatePipe.java:212)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2972)
at sun.awt.windows.WDataTransferer.imageToPlatformBytes(WDataTransferer.java:318)
at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1187)
at sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer.java:163)
at sun.awt.windows.WClipboard.setContentsNative(WClipboard.java:73)
at sun.awt.datatransfer.SunClipboard.setContents(SunClipboard.java:93)

This exception can be triggered by doing several different things with the BufferedImage, the exception listed above was triggered by sending the BufferedImage to the Clipboard, the exception can also be triggered by attempting to print the image.

The images are created using the following method;

Iterator iter = ImageIO.getImageReadersBySuffix("jpg");
if (iter.hasNext()) {
//////////////////////////////////
// Get the JPG reader
ImageReader reader = (ImageReader) iter.next();
////////////////////////////////////////////////////////
// Create the destination image, it must be TYPE_BYTE_GRAY
// to be suitable for the RipByteProcessor
BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_BYTE_GRAY);
////////////////////////////////////////////////////////
// Use the ImageReadParam object to tell the reader what
// image type we want
ImageReadParam param = reader.getDefaultReadParam();
param.setDestination(image);
/////////////////////////////////////////////////////////////
// Create an ImageInputStream object from the raw image
// byte[] and assign this input object to the reader
ImageInputStream stream = ImageIO.createImageInputStream(new ByteArrayInputStream(pRawJPGImageBytes));
reader.setInput(stream, true, true);
/////////////////////////////////////////////////////////
// Read, we expect 1 image, then do some house cleaning
image = reader.read(0, param);
stream.close();
reader.dispose();
}
}
catch (IOException e) {
}

If I create a ToolkitImage using the DefaultToolkit from the same raw JPG image bytes I do not get the exception thrown in the AffineTransformOp.

The API documantation is not very helpful, it states;

ImagingOpException is thrown if the image cannot be transformed because of a data-processing error that might be caused by an invalid image format, tile at, or image-processing operation, or any other unsupported operation.

Hmmm....?

I am using java version 1.5.0_22-b03 on Windows XP.

Any insight on how to create BufferedImages using the ImageIO package that are compatible with the AffineTransformOp would be much appreciated?

Thanks,

Ian

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ifoster
Offline
Joined: 2006-03-28

Sorry, please disregard this question.

The cause of the incompatability of the BufferedImage and the AffineTransformOp is not the decoding of the source file by the ImageIO package but some processing done on the image by the ImageJ image processing package.

I will redirect my query to the ImageJ forum. I aplogise for wasting anybodies time.

Regards,

Ian