图像和平等 [英] images and equality
问题描述
大家好,
我正在寻找一种方法来判断两个不具有对象相等性的图像对象是否是相同的图像,并且我的意思是相同的,比如原来从同一个文件加载的
。关于如何处理这个的任何想法?
TIA,
Eric
< blockquote> Eric,
我不认为有一个简单的方法可以做到这一点。如果你可以获得带有内容的
字节数组,那么你可以循环遍历字节然后
进行比较。
或者,您甚至可以将字节数组附加到MemoryStream,然后通过System.Security.Cryptography
命名空间中的哈希算法提供流b / b
然后进行比较结果。
希望这会有所帮助。
-
- Nicholas Paldino [.NET / C#MVP] >
- mv*@spam.guard.caspershouse.com
Eric Eggermann> <<无>在消息中写道
news:uQ ************** @ tk2msftngp13.phx.gbl ...
大家好,
。关于如何处理这个的任何想法?
TIA,
Eric
Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在
消息新闻:em ************** @ TK2MSFTNGP10.phx.gbl ...Eric,>
我认为没有一种简单的方法可以做到这一点。如果你可以获得带有内容的字节数组,那么你可以遍历字节和
然后进行比较。
或者,你甚至可以将字节数组附加到一个MemoryStream,然后通过System.Security.Cryptography
命名空间中的哈希算法提供该流,然后比较结果。
希望这会有所帮助。
谢谢,我会对这些事情有所了解。
Eric
这是一个展示.NET Framework强大功能的好地方,这个相当复杂的任务可以在不到十行的代码中完成:
public bool CompareImages(图片优先,图像秒)
{
System.IO.MemoryStream ms1 = new System.IO.MemoryStream();
System.IO.MemoryStream ms2 = new System.IO.MemoryStream();
first.Save(ms1,System.Drawing.Imaging.ImageFormat.Bmp);
byte [] First = ms1.ToArray();
second.Save(ms2,System.Drawing.Imaging.ImageFormat.Bmp);
byte [] Second = ms2.ToArray();
返回系统.Text.Encoding.ASCII.GetString(First)==
System.Text.Encoding.ASCII.GetString(Second);
}
" Eric Eggermann" <<无>>在消息新闻中写道:< uQ ************** @ tk2msftngp13.phx.gbl> ...大家好,我是''我正在寻找一种方法来判断两个没有对象相等的图像对象是否是相同的图像,我的意思是相同的,比如说最初是从同一个文件加载的。关于如何处理这个的任何想法?
TIA,
Eric
Hello all,
I''m looking for a way to tell whether two image objects which do not
have object equality are the same image or not, and I mean identical, say
originally loaded from the same file. Any ideas on how to approach this?
TIA,
Eric
Eric,
I don''t think that there is an easy way to do this. If you can get a
byte array with the contents, then you can cycle through the bytes and then
do a comparison.
Or, you could even attach the byte arrays to a MemoryStream, then feed
that stream through a hash algorithm in the System.Security.Cryptography
namespace and then compare the results.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Eric Eggermann >" <<none> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...Hello all,
I''m looking for a way to tell whether two image objects which do not
have object equality are the same image or not, and I mean identical, say
originally loaded from the same file. Any ideas on how to approach this?
TIA,
Eric
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:em**************@TK2MSFTNGP10.phx.gbl...Eric,
I don''t think that there is an easy way to do this. If you can get a
byte array with the contents, then you can cycle through the bytes and then do a comparison.
Or, you could even attach the byte arrays to a MemoryStream, then feed
that stream through a hash algorithm in the System.Security.Cryptography
namespace and then compare the results.
Hope this helps.
Thanks, I''ll have a whack at those.
Eric
This is a great spot to showcase the power of the .NET Framework, this
fairly complex task can be done in less than ten lines of code:
public bool CompareImages(Image first, Image second)
{
System.IO.MemoryStream ms1 = new System.IO.MemoryStream();
System.IO.MemoryStream ms2 = new System.IO.MemoryStream();
first.Save( ms1, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] First = ms1.ToArray();
second.Save( ms2, System.Drawing.Imaging.ImageFormat.Bmp );
byte[] Second = ms2.ToArray();
return System.Text.Encoding.ASCII.GetString(First) ==
System.Text.Encoding.ASCII.GetString(Second);
}
"Eric Eggermann" <<none>> wrote in message news:<uQ**************@tk2msftngp13.phx.gbl>...Hello all,
I''m looking for a way to tell whether two image objects which do not
have object equality are the same image or not, and I mean identical, say
originally loaded from the same file. Any ideas on how to approach this?
TIA,
Eric
这篇关于图像和平等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!