简体   繁体   English

C#比较两个图像

[英]C# Comparing two images

I am having an image with 500 * 500 px. 我有500 * 500像素的图像。 When I upload this image to my site it changes to 250 * 200 px. 当我将此图像上传到我的网站时,它变为250 * 200像素。 Here, I need to verify the image displayed in my site matches with the image which I chose to upload, using Selenium Web driver. 在这里,我需要使用Selenium Web驱动程序验证站点中显示的图像是否与我选择上传的图像匹配。 Probably both of the images are same. 可能两个图像都相同。

But since the pixels differs, can I able to match both of the images using Selenium Web driver? 但是由于像素不同,我可以使用Selenium Web驱动程序匹配两个图像吗?

I have tried Byte array conversion, GetHashCode() for comparing the images. 我尝试了字节数组转换GetHashCode()来比较图像。 But both Byte Array and Hash Code differs for both images. 但是,两个图像的字节数组和哈希码都不同。

Is this possible to compare and match these two images? 是否可以比较和匹配这两个图像? Will the byte array and hash code for these images differs if their size differs even though the same image is uploaded to the site? 即使将同一图像上传到站点,这些图像的字节数组和哈希码大小也会有所不同吗?

Kindly get me out of this. 请让我摆脱这个。

Thanks in advance. 提前致谢。

The byte arrays are same for both images. 两个图像的字节数组相同。 I have done a minor mistake by changing the resolution of the image manually and verified the byte array. 我通过手动更改图像的分辨率并验证了字节数组来犯了一个小错误。 So probably the byte array will be changed. 因此,可能会更改字节数组。

Now I have downloaded the image byte array using following code: 现在,我使用以下代码下载了图像字节数组:

    var src = element.GetAttribute("src");

    //downloads the byte array of the image from its src
    var file = webClient.DownloadData(src);

Now I got the byte array of the image in the site page. 现在,我在站点页面中获得了图像的字节数组。 I could compare this byte array with the physical image which I have selected to upload. 我可以将此字节数组与我选择上传的物理图像进行比较。

Thanks all for your comments. 感谢您的意见。

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

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