bmp 文件比较?
我想比较两个 bmp 文件。 我想到了两种方法:
- 比较两个文件的标头以及信息标头
- 将bmp文件转换为二进制文件,然后进行上述比较
但是,我不知道如何开始以及哪种方法更好。 如果有人能帮助我,我会很高兴!
I want to compare two bmp files. I thought of two approaches:
- to compare the header as well as the information header of the two files
- convert the bmp file to binary and then do the above comparison
But, I don't know how to start and which will be a better approach. I would be glad if someone could please help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不知道您想在哪个平台上实现此功能,但这里有一些可能有用的代码片段:
使用 C# 比较两个图像
I don't know on which platform you want to implement this, but here are some code snippets which could be useful:
Compare two images with C#
好吧,这里至少有两个选择:
图像基本相同
在这种情况下,我建议使用 splattne 的解决方案进行比较
图像通常不同,只有有时相同
在这种情况下,您可能可以通过快速比较信息标题来消除两个图像之间的任何相似性(认为“大小是否相同?”),并且仅在信息不明确时才进行完整比较(即尺寸相同)
Well, you have at least two options here:
The images are mostly the same
In this case, I'd recommend a compare using splattne's solution
The images are usually different, and only sometimes the same
In this case, it might be that you can dismiss any similarity between the two images with a quick comparison of the information header (think "is the size the same?), and only do the full comparison if the information is ambiguous (i.e. the size is the same)
您可能需要使用 .NET 3.0+ 中的扩展方法来公开所有位图上的比较方法:
You may want to use an extension method in .NET 3.0+ for this to expose the compare method on all the Bitmaps:
你在比较什么? 您想看看两张图片是否完全相同? 或者你需要差异程度吗? 对于精确匹配,如何创建和比较两个文件的哈希值?
What are you comparing for? Are you looking to see if 2 images are exactly the same? Or do you need degrees of difference? For exact matches how about creating and comparing hashes of both files?
当我有两张仅颜色深度不同的图像(一张是 32bpp,另一张是 8bpp)时,上述解决方案对我不起作用。 我找到的解决方案使用 LockBits 将所有图像转换为 32bpp,使用 Marshal.Copy() 将数据放入数组中,然后比较数组。
The above solutions didn't work for me when I had two images that only differed in color depth--one was 32bpp and the other was 8bpp. The solution I arrived at used LockBits to convert all images to 32bpp, Marshal.Copy() to get the data into an array and then just compare the arrays.