问题
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.
Thanks.
回答1:
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:
Load image from file on disk
Use System.Drawing.Image.FromFile().
Acquire an image of the screen, i.e. a screen shot
Use 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;
}
Find image inside image
See answer to this question.
回答2:
i have made a program which used a lib i coded in c# which will return the value of x and y of a small image inside a bigger image (screenshot) you can see all the details here https://www.nulled.io/topic/22223-an-advanced-image-search-library-saeedsearchdll/
来源:https://stackoverflow.com/questions/4978157/how-to-search-for-an-image-on-screen-in-c