0

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 ??

Jason Wood
  • 89
  • 3
  • 14
  • What's the output if you use the same image for `i` and `i2`? Also, use `if (Arrays.equals(i, i2)) {... }`. – Vikram Aug 22 '13 at 00:18
  • Hello Vikram.Is the approach correct so far?? Trying your suggestion. – Jason Wood Aug 22 '13 at 00:21
  • Still getting different .Am I suppose to get difference and check percentage match or something ?? – Jason Wood Aug 22 '13 at 00:24
  • Also how to convert this to colour code Like get alpha,green,blue,red from the int array i ?? – Jason Wood Aug 22 '13 at 00:26
  • You might find the answer here: [Link](http://stackoverflow.com/questions/7817248/compare-the-pixel-of-the-two-different-images-takes-too-long-time). For getting the color from a pixel: [Link](http://stackoverflow.com/a/7807442/2558882). – Vikram Aug 22 '13 at 06:47

1 Answers1

0

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?

Community
  • 1
  • 1
TheThirdOne
  • 427
  • 3
  • 10
  • I tried that too but its still different if (i.equals(i2)) { t.setText("same"); }else{ t.setText("different"); } – Jason Wood Aug 22 '13 at 00:14