c# - 是否有使用 C# 比较两个 PNG 图像的一部分而不是完整图像的功能?
问题描述
我在 Visual Studio 2019 IDE 上使用 .NET Framework 来编写用于比较两个图像的算法。
虽然如果我比较整个 png 比较工作正常,但问题是作为主副本的图片(与新生成的图像进行比较)是过去拍摄的,左上角有较旧日期和时间的时间戳,因此生成的最新图片总是会生成失败结果,即图片不匹配,因为图片上时间戳的时间差异。目前我正在使用以下内容,它适用于相同的时间戳图像
System.Drawing
System.Drawing.Imaging
Bitmap original_image = (Bitmap)Bitmap.FromFile(imageFile);
Bitmap test_image = (Bitmap)Bitmap.FromFile(testimageFile);
if(object.Equals(original_image,test_image)
return true
BitmpaData bitmapDataMasterPicture = original_image.LockBits(new Rectangle(0,0,original_image.Width,original_image.Height),ImageLockMode.ReadOnly,PixelFormat.Format32bppArgb);
BitmpaData bitmapDataTestPicture = test_image.LockBits(new Rectangle(0,0,test_image.Width,test_image.Height),ImageLockMode.ReadOnly,PixelFormat.Format32bppArgb);
for(int i = 0; i<totalBytes-1 ;i++)
if(bitmapDataMasterPicture[i] != bitmapDataTestPicture[i])
{
return false;
}
original_image.UnlockBits(bitmapDataMasterPicture);
test_image.UnlockBits(bitmapDataTestPicture);
是否有一个函数/算法来比较两个 png 图像的一部分而不是使用 C# 来比较完整?那就是跳过左上角的时间戳。
解决方案
You could crop the image or draw a solid rectangle covering the timestamp.
Graphics oGraphics= Graphics.FromImage(original_image);
Rectangle rect = new Rectangle(0, 0, 200, 200);
oGraphics.DrawRectangle(new Pen(Color.Black, 3), rect);
推荐阅读
- java - 如何从图库中选择全尺寸图像(不是缩略图)?
- c++ - 拷贝构造函数和浅拷贝
- javascript - 为什么单击事件不适用于样式化组件?
- user-interface - Flutter 中是否有 Bootstrap-sass 等价物?
- javascript - 使用 google sheet 脚本从 HTML 中提取元素值
- javascript - JavaScript 为什么不返回退出包含的函数调用?
- coldfusion - 如何遍历 SQL 查询并输出单个电子邮件
- java - Docker 容器 HttpUrlConnection 超时异常
- javascript - jquery-1.11.2.min.js 到 jquery-3.5.1.min.js :对象不支持属性或方法
- java - 从 SQL 插入数据时,为 Jtable 中的不同字段着色