0

I have for almost 2 weeks struggled with a problem in my application. I want it to click on an image, if the image is then found in a region of my screen, or preferably if the image exists on my whole entire screen. From studies i've learned that it would be better if put it into arrays. I want it to be as efficient and process cheap as possible as this is ment to run in the background for work to close annoying popups.

I have tried pretty much everything out there with no success whatsoever. The one i came the closest suceeding with was another SOF post With a user writing a module which i Could use like so:

Dim p As Point = yourBitmap.Contains(bmpYouLookFor)
If p <> Nothing Then
'...
End If

Source

Do you really have to search for a pixel and then compare your image to the one on the screen, that just seems kinda slow to me. If the pixels exists it will spend alot of time looking at false stuff.

I really hope it doesn't look like a leach I have really tried looking up forum posts, guides, referencing another language into VS, asking coder friends, google and other things for the past 1½-2 weeks

EDIT: Basicly i need to compare 1 small image with the screen. If the screen contains my image, I want to get the position of the small image and the click on it.

Community
  • 1
  • 1
  • 1
    Possible duplicate of [how-to-find-one-image-inside-of-another](http://stackoverflow.com/questions/2472467/how-to-find-one-image-inside-of-another) – bastos.sergio Aug 26 '14 at 13:15
  • I dont know c# mate, I'll talk to a friend to see if he can translate it, is possible my best bet –  Aug 26 '14 at 13:34
  • 1
    Here's a handy tool you can use. http://www.developerfusion.com/tools/convert/csharp-to-vb/ – Dave Aug 26 '14 at 13:35
  • You can also use this one http://converter.telerik.com/ – bastos.sergio Aug 26 '14 at 13:48
  • telerik gives me an error with it doesnt exist for some reason.. developerfusion is taking a veeery long time still processing, is that normal? –  Aug 26 '14 at 14:33
  • these translaters i not working for me –  Aug 26 '14 at 22:22

2 Answers2

0

If you know the locations of all images on the screen, you can retrieve the location the user clicks and then see if the point intersects with any of the rectangles (images) you know about.

myImageRectangle.Contains(myMouseClickedPoint)
Dave
  • 897
  • 8
  • 8
  • sadly i dont know for sure or do you mean roughly? –  Aug 26 '14 at 11:49
  • How are the images place on the screen? – Dave Aug 26 '14 at 11:51
  • they can be controlled by moving the popup window to (0,0) if needed be :) –  Aug 26 '14 at 11:53
  • Are you just trying to determine if your popup window is within a specific screen? Sorry. Can you clarify your question for me? – Dave Aug 26 '14 at 11:57
  • i want it to click the popup window IF it contains a certain picture :). –  Aug 26 '14 at 12:05
  • If you don't know how the image was formed, then you will have to do pixel searching. – Dave Aug 26 '14 at 12:19
  • I'm not the best with this pixel and imagesearch, what if the pixel exists elsewhere? or do i use pixelsearch and the compare two images or? –  Aug 26 '14 at 13:33
0

i have made a dll for this purpose :https://mega.co.nz/#!5YFEyQ5S!bcP-S_7EyQUsKBhxGfhpX7WvdJvUYnn8UYRmZ2RxZVQ

Here is an example of how to use it (If the x and y are 0 then image was not found and the function will return false)

Imports BitmapDetector2.Search_Image

Declare Function apimouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean

Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10

Private Function PressButton(ByRef image As Bitmap, ByRef press As Boolean, ByRef x As Integer, ByRef y As Integer)

Dim bounds As Rectangle

Dim point As New Point

Dim screenshot As System.Drawing.Bitmap

Dim graph As Graphics bounds = Screen.PrimaryScreen.Bounds screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)

graph = Graphics.FromImage(screenshot) graph.CopyFromScreen(0, 0, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)

Dim returnString As Point = BitmapDetector2.Search_Image.search(screenshot, image, 0)

If returnString.X = 0 And returnString.Y = 0 Then
Return False
Else

If press = True Then
point.X = returnString.X + x
point.Y = returnString.Y + y
Windows.Forms.Cursor.Position = point
Call apimouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call apimouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Else
point.X = returnString.X + x
point.Y = returnString.Y + y
Windows.Forms.Cursor.Position = point
End If

Return True
End If

End Function