我有一张图片和一张旋转的图片进行比较。

    if (this.img.getHeight() == img1.getWidth() && this.img.getWidth() == img1.getHeight()) {
        for (int i = 0; i < this.img.getWidth(); i++) {
            for (int j = 0; j < this.img.getHeight(); j++) {
                assertEquals(this.img.getRGB(i, j), img1.getRGB(this.img.getWidth() - j, i));
            }
        }
    }


这是我使用的循环,但是以某种方式不起作用。

图片顺时针旋转90°。

this.img是原始图片,img1是旋转的图片。有人可以帮帮我吗?提前致谢!

最佳答案

您可能需要...

img1.getRGB(this.img1.getWidth() - j, i));


代替

img1.getRGB(this.img.getWidth() - j, i));


...因为要从旋转图像的宽度向左移动,而不是原始图像的宽度(因为那样会变成高度,因此不会出现在任何x轴计算中)。

07-28 02:08
查看更多