Search code examples
javabufferedimageimage-rotation

Comparing BufferedImages with rotation


I am now working for an absurd time on this simple thing and can't get it to work. I have two BufferedImages one called image the other one rotatedImage. As you can think the one is a rotated version of the other one. I want to compare those two and check if they are (practically) the same.

this is the snippet of what i got so far:

for(int x = 0; x < image.getWidth(); x++) {
    for(int y = 0; y < image.getHeight(); y++) {
        assertEquals(image.getRGB(x, y), rotatedImage.getRGB(y, image.getWidth() - x - 1));
    }
}

Could you tell me what i got wrong? I can't see how to fix it myself :/


Solution

  • The snippet, that fixed it for me was:

    assertEquals(image.getRGB(x, y), rotatedImage.getRGB(rotatedImage.getWidth() - y - 1, x));