10

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.

Just a learner
  • 26,690
  • 50
  • 155
  • 234

2 Answers2

25

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.

Community
  • 1
  • 1
Markus Johnsson
  • 3,949
  • 23
  • 30
0

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/