问题描述
从MSDN文档,似乎既是GetHash code()和equals()还没有被重写的位图。无论是让他们被重写的图像。因此,这两个类都使用对象的版本它们只是比较引用。我是不是太相信,所以我决定火起来反射检查出来。看来MSDN是在此问题上是正确的。
From MSDN documentation, it seems as both GetHashCode() and Equals() haven't been overriden in Bitmap. Neither have them been overriden in Image. So both classes are using the Object's version of them just compares references. I wasn't too convinced so I decided to fire up Reflector to check it out. It seems MSDN is correct in that matter.
那么,有没有为什么MS家伙不会实行比较逻辑,至少在Bitmap类的任何特别的原因吗?我觉得这是对图像还挺接受的,因为它是一个抽象类,但没有这么多的Bitmap类。我可以在很多情况下,计算散列code可以是一个昂贵的操作看,但它会是好的,如果它使用的一些类型的缓存。
So, is there any special reason why MS guys wouldn't implement "comparison logic", at least for the Bitmap class? I find it is kinda acceptable for Image, as it is an abstract class, but not so much for the Bitmap class. I can see in a lot of situations calculating the hash code can be an expensive operation, but it'd be alright if it used some kind of caching.
在想比较2位图,我将不得不诉诸不必在画面比较执行所有像素中的每一个?
When wanting to compare 2 bitmaps, will I have to resort to having to run all over the picture comparing each one of its pixels?
感谢
推荐答案
让我们前后翻页的问题;有没有什么特别的原因,他们的将会的实施这样的事?
Let's flip that question around; is there any special reason why they would implement such a thing?
有关一件事,那将是非常,非常昂贵的计算哈希值,使得这一切,但无用的哈希表等。只要试着去想像在1920x1200的位图整体转换这样做;即使的一次的做每一个位图将减缓程序抓取。我预计9次了10年,当有人来比较两个位图,他们要引用的平等,而不是逐个像素值相等。
For one thing, it would be very, very expensive to compute the hash, making it all but useless for hash tables and the like. Just try to imagine doing this on a whole slew of 1920x1200 bitmaps; doing it even one time for each bitmap would slow the program to a crawl. I would expect that 9 times out of 10, when somebody has to compare two bitmaps, they want reference equality, not pixel-by-pixel value equality.
和你是指你的问题是什么是不是懒惰的评价,它的缓存。缓存是实现一个不平凡的功能,每个功能开始于减去100点的。
And what you refer to in your question isn't lazy evaluation, it's caching. Caching is a non-trivial feature to implement, and every feature starts at minus 100 points.
通过这些想法,我的答案,这将是该方法没有被覆盖,因为覆盖的版本将不会是特别有用的人不少,相对于实施和维护这样的功能的成本。如果你真的想逐像素比较(或校验,或者类似的东西),那么你可以随时实现它们自己在10行左右。
With all that in mind, my answer to this would be that the methods aren't overridden because the overridden versions wouldn't be particularly useful to many people, relative to the cost of implementing and maintaining such a feature. If you really want pixel-by-pixel comparisons (or checksums, or similar things), then you can always implement them yourself in 10 lines or so.
这篇关于是什么原因图像和位图类不实现自定义平等/散列code逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!