简体   繁体   中英

Problems rotating tiff image

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);

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM