covert array pixel from image to color to compare

499 views Asked by At

I am using the code below to get pixel by supplying the bitmap

public int[] foo(Bitmap bitmapFoo) {
    int[] pixels;
  //  Bitmap bitmapFoo ;            
    int height = bitmapFoo.getHeight();
    int width = bitmapFoo.getWidth();

    pixels = new int[height * width];

    bitmapFoo.getPixels(pixels, 0, width, 1, 1, width - 1, height - 1); 
   return pixels;

}

now how do I compare it to similar image??

                           int[] i = foo(img2);
                int[] i2 = foo(img1);

                if (i==i2) {

                    txt.setText("same");
                }else{


                    txt.setText("different");
                }

Even if the image is similar not same it still shows different .How to avoid it ??

Is the comparison correct ?? or I am doing something wrong ??

1

There are 1 answers

1
TheThirdOne On

I believe the problem is that you are comparing objects. When you create two objects independently they are not equal.

If you have i.equals(i2) instead it should work as intended.

.equals compares values rather than testing to see if the objects are actually the same object

EDIT: I forgot that you may have to override .equals to achieve the desired result. This question may help you. Why do we have to override the equals() method in Java?