简体   繁体   English

隐式阵列像素从图像到颜色进行比较

[英]covert array pixel from image to color to compare

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 ?? 还是我做错了什么?

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. 如果您有i.equals(i2)它应该可以正常工作。

.equals compares values rather than testing to see if the objects are actually the same object .equals比较值而不是测试以查看对象是否实际上是同一对象

EDIT: I forgot that you may have to override .equals to achieve the desired result. 编辑:我忘记了您可能必须重写.equals才能获得所需的结果。 This question may help you. 这个问题可能对您有帮助。 Why do we have to override the equals() method in Java? 为什么我们必须重写Java中的equals()方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM