比较两个图像是相同或不 [英] compare two images is same or not

查看:166
本文介绍了比较两个图像是相同或不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何比较两个字符串是相同或not.this被编码比较两个字符串 TextView的T,T1;

I know how to compare two string is same or not.this is coding for compare two strings TextView t,t1;

String s,s1;
s=t.getText().toString();
s1=t1.setText().toString();
if(s.equals(s1)){
   t.setText("equal");
}
else{
   t.setText("not equal");
}

我需要的编码比较两个图像是相同或not.please早给我

i need the coding for compare two images are same or not.please give me early

推荐答案

检查高度匹配,如果不返回false。然后,检查宽度匹配,如果没有,则返回false。然后检查每一个像素,直到你找到一个不匹配。当你这样做,返回false。如果每个像素相匹配,返回true。

Check that the height matches, if not return false. Then, check if the width matches, and if not, return false. Then check each pixel until you find one that doesn't match. When you do, return false. If every pixel matches, return true.

伪code

bool imagesAreEqual(Image i1, Image i2)
{
    if (i1.getHeight() != i2.getHeight) return false;
    if (i1.getWidth() != i2.getWidth) return false;

    for (int y = 0; y < i1.getHeight(); ++y)
       for (int x = 0; x < i1.getWidth(); ++x)
            if (i1.getPixel(x, y) != i2.getPixel(x, y)) return false;

    return true;
}

在现实中,你可能需要把图像作为一个二维数组,如果你可以,只是比较字节。我不知道在Android形象的API,但getPixel可能​​是缓慢的。

In reality, you probably want to treat the image as a two dimensional array if you can, and just compare bytes. I don't know the Android image API, but getPixel might be slow.

这篇关于比较两个图像是相同或不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆