Skip to main content

Unable to resize .tif image

1 reply [Last post]
Joined: 2010-07-21

I am unable to resize .tiff image. Following is my code

File f = new File("D:/Work/YoursGallery/sample1.tif");
SeekableStream ss = new FileSeekableStream(f);
TIFFDecodeParam tp = null;
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, tp);
int numofpages = dec.getNumPages();
for (int i = 0; i < numofpages; i++) {
RenderedImage op = dec.decodeAsRenderedImage(i);
TiledImage tim = new TiledImage(op, 512, 512);
op = tim;
ParameterBlock pb = new ParameterBlock();
pb.addSource(op); pb.add(1.0f); pb.add(1.0f);
ImageLayout la = new ImageLayout(); la.setTileWidth(512); la.setTileHeight(512);
RenderingHints rhi = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, la);
RenderedImage sri = JAI.create("subsampleBinaryToGray", pb, rhi);
I am getting following exceptions:
java.lang.IllegalArgumentException: SubsampleBinaryToGray src image must have MultiPixelPackedSampleModel.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-07-21

Here is the sample .tif file

Can anyone tell what is the issue with code. any suggestions?