I need to quickly tell if one Slick2D image has the same pixel data as another Slick2D image. The .equals()
method does not accomplish this. Is there a way to do this?
Asked
Active
Viewed 138 times
1 Answers
0
Try this:
public static boolean same(Image i1, Image i2) {
return i1.getTexture().getTextureData().equals(i2.getTexture().getTextureData());
}
Why the creators of slick made it impossible to get the pixels from the image I do no know, but this might work :)
-
You could try iterating through the textureData, checking each byte individually, then if one doesn't match, return false, if all of them match, return true. Also make sure you check the size of them before iterating, for if the sides are different, it would throw an outOfBoundsException. Might look something like this `for(int i = 0; i < i1.getTexture.getTextureData().length; i++) { if(i1.getTexture.getTextureData()[i] != i2.getTexture.getTextureData()[i]) return false; } return true;` – Rock48 May 18 '14 at 16:34