简体   繁体   English

检查位图是否已被修改

[英]Check if a Bitmap has been modified

I have a class that wraps around a Bitmap and I would like to have a way of knowing if the bitmap has been changed (via SetPixel or GDI+). 我有一个环绕位图的类,我想有一种方法来了解位图是否已更改(通过SetPixel或GDI +)。

I don't need to know exactly when it happens, I just need a way to tell if it has happened since the last check. 我不需要确切地知道它何时发生,我只需要一种方法就可以知道自上次检查以来它是否已经发生。

Now, I'm assuming that something like that isn't already packed in the Bitmap class, so what would be the best way to solve this problem? 现在,我假设Bitmap类中尚未包含类似的内容,那么解决此问题的最佳方法是什么?

I could provide my own wrapper functions for GetPixel and SetPixel, but then I'd have no idea if the Bitmap was changed using GDI. 我可以为GetPixel和SetPixel提供自己的包装函数,但随后我不知道是否使用GDI更改了位图。 I COULD make a wrapper for that too but that really seems like a huge overkill. 我也可以为此做一个包装,但这确实是一个巨大的过大杀伤力。

Another possible option would be to save a copy and then check pixel by pixel. 另一个可能的选择是保存副本,然后逐像素检查。 This would obviously work and would be trivial to write but it's much too slow for my needs. 这显然可以工作,并且编写起来很琐碎,但是对于我的需求来说太慢了。

You should use a hash or check sum. 您应该使用哈希或校验和。 There are some easy ways to do this but I think the simplest way would be to have a string hash property in your class then call GetHashCode() on the bitmap/binary string/whatever container you're storing it in. Set it to the classes property, check the current hashcode against that value to see if anything has changed. 有一些简单的方法可以做到这一点,但我认为最简单的方法是在类中具有string hash属性,然后在要存储它的位图/二进制字符串/任何容器上调用GetHashCode() 。 classes属性,对照该值检查当前哈希码,看是否有任何变化。 You could also write your own little checksum function or choose from (I'm sure) a vast array of third party options. 您也可以编写自己的小校验和函数或从(我确定)各种各样的第三方选项中进行选择。

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

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