Javafx how to check equality of images?

for (int i = 0; i < image1Width; i++)
  for (int j = 0; j < image1Height; j++)
    if (image1.getPixelReader().getColor(i, j) != image2.getPixelReader().getColor(i, j)) return false;


This is what I have at the moment. I pass the function two images (javafx.scene.image.Image). This means it should never return false when the images are the same. Unfortunately this returns false when I pass the same image to it.



source to share

1 answer

You need

if (!image1.getPixelReader().getColor(i, j).equals(image2.getPixelReader().getColor(i, j))) return false;



if (image1.getPixelReader().getArgb(i, j) != image2.getPixelReader().getArgb(i, j)) return false;


The second version could be faster.



All Articles