I use JAI to load multi-page TIFF images
File file = workArea[0]; SeekableStream s = new FileSeekableStream(file); TIFFDecodeParam param = null; ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param); //first page RenderedImage op1 = new NullOpImage(dec.decodeAsRenderedImage(0), null, OpImage.OP_IO_BOUND, null); BufferedImage pg1 = new BufferedImage(op1.getWidth(), op1.getHeight(), BufferedImage.TYPE_INT_RGB); pg1.getGraphics().drawImage((Image) op1, 0, 0, null);
However, in the last line, I get a runtime error:
Exception in thread "main" java.lang.ClassCastException: javax.media.jai.MullOpImage cannot be cast to java.awt.Image
I clean up the RenderedImage after trying to set the BufferedImage, so I don't need a RenderedImage if there is another way to do this.
I tried:
pg1.setData(op1.getData());
and this gives an ArrayIndexOutOfBoundsException exception. I'm not sure why, since pg1 width and height are set to op1, but there is probably a very good reason.
source share