Reputation: 117
I have found a code to rotate a tiff image clockwise but its taking so much time and even scrolling the image in jscrollpanel is also very slow.
1.So is there any easy method to rotate a tiff image or
2.Any tweaking is needed in the below code to rotate it quickly.
ReadableByteChannel rBytChnl = Channels.newChannel(url);
ByteBuffer buffer = ByteBuffer.allocate(4096 * 1024);
rBytChnl.read(buffer);
byte[] data = buffer.array();
SeekableStream stream = new ByteArraySeekableStream(data);
ParameterBlock pb = new ParameterBlock();
pb.add(stream);
RenderedOp op = JAI.create("tiff", pb);
TransposeType type = TransposeDescriptor.ROTATE_90;
ParameterBlock pb1 = new ParameterBlock();
pb1.addSource(op);
pb1.add(type);
pb1.add(new InterpolationBilinear());
image = JAI.create("transpose", pb1, null);
Upvotes: 1
Views: 1570
Reputation: 117
I have adjusted the affine transform to meet my needs and its working fine. This is only for 90 degree clockwise rotation and for other needs change the code accordingly.
PlanarImage pi = PlanarImage.wrapRenderedImage(image);
BufferedImage bi = pi.getAsBufferedImage();
AffineTransform at = new AffineTransform();
at.translate(-(image.getWidth() - image.getHeight()) / 2, (image.getWidth() - image.getHeight()) / 2);
at.rotate(Math.toRadians(90),bi.getWidth()/2,bi.getHeight() / 2);
AffineTransformOp opRotated = new AffineTransformOp(at,
AffineTransformOp.TYPE_BILINEAR);
image = opRotated.filter(bi, null);
Upvotes: 3