Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javafx how to test image equality?

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 that this should never return false when the images are the same. Unfortunately, this returns false when I pass it the same image.

Thanks.

like image 892
jjaken Avatar asked Sep 11 '25 06:09

jjaken


1 Answers

You need

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

or

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

The second version may be faster.

like image 134
James_D Avatar answered Sep 12 '25 20:09

James_D