Results 1 to 11 of 11

Thread: Find an image on screen

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    17

    Find an image on screen

    Hi,

    I am trying to code something that will check if a png image is visible on your screen.

    So lets say the image is a purple square with yellow circles in it (random example). It will keep checking to see if the same purple square with yellow circles is on your screen.

    What i'm trying to say is, instead of checking for one pixel color, check to see if the actual image is on there (maybe multiple pixels?)

    Thanks.

  2. #2
    Lively Member
    Join Date
    Oct 2007
    Posts
    64

    Re: Find an image on screen

    What exactly are you trying to accomplish?

    When you say on the screen are you saying if it appears anywhere? Like as in any application "Word, Excel, IE, Wordpad etc" or one specific application you are monitoring. Or is just your own application you are trying to check images?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    17

    Re: Find an image on screen

    Quote Originally Posted by tylerpestell View Post
    What exactly are you trying to accomplish?

    When you say on the screen are you saying if it appears anywhere? Like as in any application "Word, Excel, IE, Wordpad etc" or one specific application you are monitoring. Or is just your own application you are trying to check images?
    Basically, if the image is shown. So lets say I took a screenshot of my whole screen. it would search that screenshot to see if there is a certain image in it.

    Like lets say I have a bunch of programs open, and there is some shape it needs to find, it would look to see if that shape is on the screen itself, not specifically in applications, but if that pixel combination is on the screen.

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Find an image on screen

    How fast you need this to be? for example an aimbot should be almost real time, you need something this fast or some seconds would still be ok?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    17

    Re: Find an image on screen

    Quote Originally Posted by jcis View Post
    How fast you need this to be? for example an aimbot should be almost real time, you need something this fast or some seconds would still be ok?
    A few seconds would be fine. However, I would really appreciate it if you would show me how to do this in both cases.

    Thanks.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Find an image on screen

    For finding a simple picture (2D) i would just mark some representative pixels, say 8 pixels and store their position, then when i find those 8 pixels in the correct position on the screen (given an x/y offset) i know i found the picture, this will be faster because you have for example 8 pixels, not all of them. Then for example you scan the desktop image looking for the 1st pixel, if found then go to 2nd pixel coordinates and check there, then the 3rd pixel, and you keep like this until all 8 pixels has been found, then you can say you found your image. Maybe 3 or 4 pixels could also be enough.

    Now, if you need to work on a 3D world, like 1st person shooter games then things will be much harder, the best for aimbots is finding a pixel, because a pixel is always a pixel, a picture (like the enemy's head for example) will depend on distance, this is the big problem, if the enemy is closer the picture is bigger otherwise it's smaller, finding a picture at any distance will be almost impossible (I think).
    Last edited by jcis; May 17th, 2012 at 06:15 PM.

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Find an image on screen

    For 2D, some steps:

    1) Determine your representative pixels, store color, x pos and y pos for each and store them somewhere, an array for example.
    2) Take an screenshot as bitmap using something like this
    3) Use Fastpix (submitted by boops boops to the Codebank) for fast pixel processing. With this you'll create a loop checking each pixel in the screenshot bitmap, when you find the first see if the second is also in position and so on, if you find all of them then you found your bitmap, if not then continue looping.

    Assume your 1st representative pixel is at X=40+xOffset and Y=20+YOffset, then you know that moving 40 towards LEFT and 20 towards TOP you'll find the first point (top-left corner) for your image found in the screen, and if you need the center it will be:

    X = X0 + YourImageWidth / 2
    Y = Y0 + YourImageHeight / 2
    Last edited by jcis; May 17th, 2012 at 07:02 PM.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    17

    Re: Find an image on screen

    Quote Originally Posted by jcis View Post
    For 2D, some steps:

    1) Determine your representative pixels, store color, x pos and y pos for each somewhere, an array for example.
    2) Take an screenshot as bitmap using something like this
    3) Use Fastpix (submitted by boops boops to the Codebank) for fast pixel processing. With this you'll create a loop checking each pixel in the screenshot bitmap, when you find the first see if the second is also in position and so on, if you find all of them then you found your bitmap, if not then continue looping.

    Assume your 1st representative pixel is at X=40 / Y=20, then you know that moving 40 towards LEFT and 20 towards TOP you'll find the first point (top-left corner) for your image found in the screen, and if you need the center it will be:

    X = X pos + YourImageWidth / 2
    Y = Y pos + YourImageHeight / 2
    But how can I check (for step 1) what are the pixel colors for certain coordinates.

  9. #9
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Find an image on screen

    Quote Originally Posted by yoni201 View Post
    But how can I check (for step 1) what are the pixel colors for certain coordinates.
    I gave you the code to do that in this post in another thread and you said it didn't work for you. Maybe that code doesn't work in vs2008 express? i'm using vs2010

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    17

    Re: Find an image on screen

    Quote Originally Posted by jcis View Post
    I gave you the code to do that in this post in another thread and you said it didn't work for you. Maybe that code doesn't work in vs2008 express? i'm using vs2010
    Yeah that didn't work for me...

    Could you maybe send me the EXE program?

    basically you put an image into a picturebox and once you click a button it puts the RGB values of the pixels of all the coordinates into a listbox.

    Thanks man.

  11. #11
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Find an image on screen

    No, you can't ask for compiled code every time something doesn't work, you need to make it work yourself. Search on google, search the forums, you have many tools at your dispossal to help you understand why those 3 lines of code are not working for you. Step 1 is the easier one.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width