Home > Software engineering >  Pray god help, about vb to find color screen
Pray god help, about vb to find color screen

Time:09-27

Option Explicit

Private Type BITMAPINFOHEADER '40 bytes
BiSize As Long
BiWidth As Long
BiHeight As Long
BiPlanes As Integer
BiBitCount As Integer
BiCompression As Long
BiSizeImage As Long
BiXPelsPerMeter As Long
BiYPelsPerMeter As Long
BiClrUsed As Long
BiClrImportant As Long
End Type
Private Type RGBQUAD
RgbBlue As Byte
RgbGreen As Byte
RgbRed As Byte
RgbReserved As Byte
End Type
Private Type BITMAPINFO
BmiHeader As BITMAPINFOHEADER
BmiColors As RGBQUAD
End Type
Private Type POINT
As an Integer X
Y As Integer
End Type
Private Const DIB_RGB_COLORS As Long=& amp; H0 & amp;
Private Const BI_RGB As Long=& amp; H0 & amp;
Private Const OBJ_BITMAP As Long=& amp; H7 & amp;
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _
ByVal nNumScans As Long, ByVal lpBits, As Long As lpBI BITMAPINFO, ByVal wUsage As Long As Long)
Private Declare Function GetCurrentObject Lib "gdi32" (ByVal HDC As Long, ByVal uObjectType As Long) As Long
Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (Destination As Any Source, As Any, ByVal Length As Long)
Private Declare Function GetDC Lib "user32" (ByVal HWND) As Long As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal HWND As Long, ByVal HDC) As Long As Long
Private Function findColor (ByVal HDC As Long, ByVal Width As an Integer, ByVal Height As an Integer, ByVal find_Color As Long, ByRef retClr () As POINT) As Long
Dim bi As BITMAPINFO
Dim LngCol As Long, hMap As Long, lenBuf As Long, r As Long, s As Long
Dim bmpBuf () As Byte
Dim X As an Integer, Y As Integer
Erase retClr
Find_Color=(& amp; HFF And find_Color) * & amp; H10000 + (& amp; HFF00 & amp; And find_Color) + (& amp; HFF0000 And find_Color)/& amp; H10000
With bi. BmiHeader
BiSize=Len (bi. BmiHeader)
. BiWidth=Width
. BiHeight=Height
. The biPlanes=1
. BiBitCount=24
The biCompression=BI_RGB
End With
LenBuf=CLng Height (Width) * * 3
ReDim bmpBuf (lenBuf - 1)
HMap=GetCurrentObject (HDC, OBJ_BITMAP)
GetDIBits HDC, hMap, 0, bi bmiHeader. BiHeight, VarPtr (bmpBuf (0)), bi, DIB_RGB_COLORS
Dim aa As Long
For Y=Height To Step 1-1
For X=1 To Width
CopyMemory LngCol bmpBuf (r), 3
If LngCol=find_Color Then
ReDim Preserve retClr (s)
With retClr (s)
X=X
. Y=Y
End With
S=s + 1
Aa=3
'the Exit For
End the If
R=r + 3
Next
'If aa=3 Then
'the Exit For
'End If

Next
Erase bmpBuf
FindColor=s
End the Function
Private Sub Command1_Click ()
On the Error Resume Next
As Long Dim a, b As Long
A=0
B=0


Dim HDC As Long, sint As Single, retClr () As POINT, ret As Long
Sint=Timer
'the HDC=GetDC (526622)
HDC=GetDC (0)
'the ret=findColor (HDC, 640, 480, & amp; HF7F718, retClr ())
Ret=findColor (HDC, 1280, 800, & amp; H28394D, retClr ())
ReleaseDC 0, HDC
If ret & lt;> 0 Then
MoveTo retClr (a). X, retClr (a).
YMsgBox "the color points:" & amp; Ret & amp; "Is:" & amp; (Timer - sint) & amp; "Coordinates" & amp; RetClr (a). X & amp; "" & amp; RetClr (a).
Y'MsgBox "the color points:" & amp; Ret & amp; "Is:" & amp; (Timer - sint) '& amp; "Coordinates" & amp; RetClr (a). X & amp; "" & amp; RetClr (a).
yThe Else


MsgBox "not found"
End the If
End Sub

This is the screen to find a color code, how to implement by looking for a color adjacent the coordinates of the fixed found the purpose of color coordinates,

CodePudding user response:

Vb to do such a thing is slower than the C/C + +,

CodePudding user response:

The realization of the function of reference in the http://www.autohotkey.com source ImageSearch,

CodePudding user response:

That's not the vb code

CodePudding user response:

How to implement the by color to find the coordinates of the adjacent color fixed find color coordinates
the purpose of
I don't understand the meaning of this sentence,
Am I still need to "study", learning Chinese grammar...

CodePudding user response:

Finally returned to the coordinates of the preceding code is the last one color coordinate, after, I want to find a color by the color near other coordinate the color I want to find a fixed coordinate,
Use getpixel I found wrong, but after the first point with the debug output getpixel coordinates, color is right, if use to judge is not
  • Related