【问题标题】:Problems rotating tiff image旋转 tiff 图像的问题
【发布时间】:2011-11-23 05:41:08
【问题描述】:

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

【问题讨论】:

  • 我会将图像渲染成 BufferedImage,然后旋转它。
  • 我做了同样的事情,但是像素增加了,图像的一部分被截断了。我需要一个像素没有任何变化的图像。

标签: java applet rotation tiff affinetransform


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    相关资源
    最近更新 更多