请给一个C#的找图代码(类似大漠找图)

时间2023-03-21 10:16:48 提问来自 加州San Jose 的网友 分类ChatGPT提问 浏览200 热度0
using System; using System.Drawing; namespace FindImageInCSharp { class Program { static void Main(string[] args) { // 创建一个图片对象,用来表示要查找的目标图片: Bitmap target = new Bitmap("target.jpg"); // 创建一个图片对象,用来表示要搜索的范围: Bitmap searchArea = new Bitmap("searchArea.jpg"); // 遍历搜索范围中的每一个像素: for (int x = 0; x < searchArea.Width - target.Width; x++) { for (int y = 0; y < searchArea.Height - target.Height; y++) { // 比较当前位置及其周围所有像素是否与目标图片匹配: bool match = true; // 用于标识当前位置是否匹配目标图片 for (int i = 0; i < target.Width && match == true ; i++) { // 遍历当前位置及其周围所有像素 for (int j = 0; j < target.Height && match == true ; j++) { if (!target[i, j].Equals(searchArea[x + i, y + j])){ // 如果任意一个像素不匹配则该位置不匹配 match = false; break; } } } if (match){ Console.WriteLine("Found at " + x + "," + y); } } } }}

AI智能问答网免责声明:
以上内容除特别注明外均来源于网友提问、ChatGPT回答,权益归原著者所有,本站仅作效果演示和欣赏之用;
若以上展示有冒犯或侵害到您,敬请联系我们进行删除处理,谢谢!

上一篇 绘制一张常见的企业网络拓扑图(1张) 下一篇 搜索框的用法