旋转 tiff 图像时出现问题

发布于 2024-12-17 08:38:37 字数 825 浏览 4 评论 0原文

我找到了一个代码来顺时针旋转 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);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2024-12-24 08:38:37

我已经调整了仿射变换以满足我的需要并且它工作正常。这仅适用于顺时针旋转 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文