1

我找到了一个顺时针旋转tiff 图像的代码,但是它花费了很多时间,甚至在 jscrollpanel 中滚动图像也很慢。

1.那么有什么简单的方法来旋转 tiff 图像或

2.在下面的代码中需要进行任何调整以快速旋转它。

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

1 回答 1

3

我已经调整了仿射变换以满足我的需要及其正常工作。这仅适用于顺时针旋转 90 度,其他需要相应地更改代码。

       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);
于 2011-11-24T11:56:52.490 回答