如何在C#屏幕上搜索图像? [英] How to search for an image on screen in C#?

查看:113
本文介绍了如何在C#屏幕上搜索图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#或其他.NET语言(例如Powershell)在屏幕上搜索图像.像我这样在文件系统中给出图像位置,并且代码将整个屏幕视为图像,并在大图像(屏幕)中的文件系统中搜索图像,然后返回屏幕上的图像位置.我在.net类中找不到这种东西.

I want to search for an image on screen using C# or other .NET languages(like powershell). Something like i give an image location in the file system and the code consider the whole screen as an image and search the image in the file system in the big image(the screen) then returns the image position on screen. I can't find this kind of things in the .net classes.

谢谢.

推荐答案

这是一个非常具体的问题,这就是为什么您无法在.NET Framework中找到它的原因.您应该将问题分解成小块:

This is a pretty specific problem, which is why you won't find it in the .NET Framework. You should break down your problem in smaller pieces:

从磁盘上的文件加载图像

使用 System.Drawing.Image.FromFile().

获取屏幕图像,即屏幕截图

使用 System.Drawing.Graphics.CopyFromScreen( ):

Bitmap CaptureScreen()
{
    var image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
    var gfx = Graphics.FromImage(image);
    gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
    return image;
}

在图像内部查找图像

请参见此问题的答案.

这篇关于如何在C#屏幕上搜索图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆