Post by zeak on May 16, 2019 5:18:55 GMT
Hi Steve,
This is continuing on from our private chat about finding text on a screen or image.
I've found this bit of code about finding a image written in VB, I'm not sure what code format you are using tho (C++, C#, Python)
Module ImageFunctions
02 Public Declare Function PrintWindow Lib "user32" Alias "PrintWindow" (ByVal hwnd As IntPtr, ByVal hDC As IntPtr, ByVal nFlags As UInt32) As Boolean
03 Public Function FindImage(ByVal ImageString As String) As Boolean
04 GetHandle()
05 Dim Bitmap As Bitmap = New Bitmap(620, 334)
06 Dim g As Graphics = Graphics.FromImage(Bitmap)
07 Dim hwndb As IntPtr = g.GetHdc
08 Dim bool As Boolean
09 PrintWindow(hWnd, hwndb, 0)
10 g.ReleaseHdc()
11 Dim Image As Bitmap = New Bitmap(ImageString)
12 Bitmap.Save("Print.bmp")
13 For I = 0 To Bitmap.Width - 1
14 For J = 0 To Bitmap.Height - 1
15 If Bitmap.GetPixel(I, J) = Image.GetPixel(0, 0) Then
16 bool = Compare(I, J, Bitmap, Image)
17 If bool = True Then
18 Return True
19 End If
20 End If
21 Next
22 Next
23 End Function
24 Public Function Compare(ByVal X As Long, ByVal Y As Long, ByVal pixel As Bitmap, ByVal pixela As Bitmap) As Boolean
25 Dim xx, xy As Long
26 Dim cx As Long = X
27 Dim cy As Long = Y
28 Dim exitf, Match As Boolean
29 For cy = Y To Y + pixela.Width - 2
30 For cx = X To X + pixela.Height - 2
31 If xx >= pixela.Height - 1 Then
32 xx = 0
33 xy += 1
34 ElseIf xy >= pixela.Width - 1 Then
35 Compare = True
36 exitf = True
37 Exit For
38 End If
39 On Error Resume Next
40 Dim pixel1 As Color = pixel.GetPixel(cx, cy)
41 Dim pixel2 As Color = pixela.GetPixel(xx, xy)
42 xx += 1
43 Match = (pixel1.R = pixel2.R) And (pixel1.G = pixel2.G) And (pixel1.B = pixel2.B)
44 If Match = False Then
45 exitf = True
46 Exit For
47 End If
48 Next
49 If exitf = True Then
50 Exit For
51 End If
52 Next
53 Match = False
54 If Compare = True Then
55 clickx = (cx - X) / 2
56 clicky = (cy - Y) / 2
57 End If
58 End Function
59 End Module
My thought was if it could use the same sort of user interface as pixel range but also ask for either a file or text string for comparison.