【问题标题】:Rotate BufferedImage without lose pixels [duplicate]旋转 BufferedImage 而不会丢失像素 [重复]
【发布时间】:2014-11-25 15:47:38
【问题描述】:

您好,我尝试在 Java 中旋转 BufferedImage,但一切正常。这是我的代码:

public void RotateImageNDegrees(String angulo){
        AffineTransform tx = new AffineTransform();

        tx.rotate(Double.parseDouble(angulo), bimage.getWidth() / 2, bimage.getHeight() / 2);

        AffineTransformOp op = new AffineTransformOp(tx,
        AffineTransformOp.TYPE_BILINEAR);
        bimage = op.filter(bimage, null); 

        drawImageInFrame(bimage);   //Use bimage width and height to paint in a Frame
}

方法“drawImageInFrame(bimage);”绘制图像,使用 bimage 宽度和高度来设置 JFrame 的大小。

这是它返回的内容:

http://i61.tinypic.com/2ic3590.jpg

但我需要的是这样的:

http://i59.tinypic.com/14l7wuu.jpg

谢谢大家=D

【问题讨论】:

    标签: java swing rotation jframe bufferedimage


    【解决方案1】:

    只是一个猜测,但您可能必须在每一侧将框架的大小重新调整为 root(height^2 + width^2) 以容纳整个图像,因为它似乎是在一个框架中显示图像那仍然是未旋转图像的宽度和高度。不过自己没试过。

    【讨论】:

    • 嗨我已经尝试过你所说的设置大小(1000,1000)以确保它有足够的空间来绘制,但它仍然看起来像这样:i62.tinypic.com/2userkj.jpg我认为问题是它采用负值绘制。还是谢谢=D
    • 我知道这是一篇旧帖子。但为了帮助未来的读者,我认为问题不在于像素丢失,而在于像素不在屏幕上。我相信你必须改变图像的 x 和 y 值以确保显示其余部分。
    猜你喜欢
    • 2017-12-30
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 2017-03-31
    • 2018-04-23
    相关资源
    最近更新 更多