GetPixel Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long 说明 在指定的设备场景中取得一个像素的RGB值 返回值 Long,指定点的RGB颜色。如指定的点位于设备场景的剪切区之外,则返回CLR_INVALID 参数表 参数 类型及说明 hdc Long,一个设备场景的句柄 x,y Long,逻辑坐标中要检查的点
option Explicit''Add a Timer Control to a Form, then use this code And point to anywhere on your screen to have 'the RGB value appear In the Forms Caption. ' private Type POINTAPI x as Long y as Long End Type ' private Declare Function GetPixel Lib "gdi32" (byval hdc as Long, _ byval x as Long, byval y as Long) as Long private Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long private Declare Function GetWindowDC Lib "user32" (byval hwnd as Long) as Long ' private Sub Form_Load() Timer1.Interval = 100 End Sub ' private Sub Timer1_Timer() Dim tPOS as POINTAPI Dim sTmp as string Dim lColor as Long Dim lDC as Long ' lDC = GetWindowDC(0) Call GetCursorPos(tPOS) lColor = GetPixel(lDC, tPOS.x, tPOS.y) Label2.BackColor = lColor ' sTmp = Right$("000000" & Hex(lColor), 6) Caption = "R:" & Right$(sTmp, 2) & " G:" & mid$(sTmp, 3, 2) & " B:" & Left$(sTmp, 2) End Sub
option Explicit ' 'Add a Timer Control to a Form, then use this code And point to anywhere on your screen to have 'the RGB value appear In the Forms Caption. ' private Type POINTAPI x as Long y as Long End Type ' private Declare Function GetPixel Lib "gdi32" (byval hdc as Long, _ byval x as Long, byval y as Long) as Long private Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long private Declare Function GetWindowDC Lib "user32" (byval hwnd as Long) as Long ' private Sub Form_Load() Timer1.Interval = 100 End Sub ' private Sub Timer1_Timer() Dim tPOS as POINTAPI Dim sTmp as string Dim lColor as Long Dim lDC as Long ' lDC = GetWindowDC(0) Call GetCursorPos(tPOS) lColor = GetPixel(lDC, tPOS.x, tPOS.y) Label2.BackColor = lColor ' sTmp = Right$("000000" & Hex(lColor), 6) Caption = "R:" & Right$(sTmp, 2) & " G:" & mid$(sTmp, 3, 2) & " B:" & Left$(sTmp, 2) End Sub
getdc(0)
getpiexl
说明
在指定的设备场景中取得一个像素的RGB值
返回值
Long,指定点的RGB颜色。如指定的点位于设备场景的剪切区之外,则返回CLR_INVALID
参数表
参数 类型及说明
hdc Long,一个设备场景的句柄
x,y Long,逻辑坐标中要检查的点
'the RGB value appear In the Forms Caption.
'
private Type POINTAPI
x as Long
y as Long
End Type
'
private Declare Function GetPixel Lib "gdi32" (byval hdc as Long, _
byval x as Long, byval y as Long) as Long
private Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long
private Declare Function GetWindowDC Lib "user32" (byval hwnd as Long) as Long
'
private Sub Form_Load()
Timer1.Interval = 100
End Sub
'
private Sub Timer1_Timer()
Dim tPOS as POINTAPI
Dim sTmp as string
Dim lColor as Long
Dim lDC as Long
'
lDC = GetWindowDC(0)
Call GetCursorPos(tPOS)
lColor = GetPixel(lDC, tPOS.x, tPOS.y)
Label2.BackColor = lColor
'
sTmp = Right$("000000" & Hex(lColor), 6)
Caption = "R:" & Right$(sTmp, 2) & " G:" & mid$(sTmp, 3, 2) & " B:" & Left$(sTmp, 2)
End Sub
'
'Add a Timer Control to a Form, then use this code And point to anywhere on your screen to have
'the RGB value appear In the Forms Caption.
'
private Type POINTAPI
x as Long
y as Long
End Type
'
private Declare Function GetPixel Lib "gdi32" (byval hdc as Long, _
byval x as Long, byval y as Long) as Long
private Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long
private Declare Function GetWindowDC Lib "user32" (byval hwnd as Long) as Long
'
private Sub Form_Load()
Timer1.Interval = 100
End Sub
'
private Sub Timer1_Timer()
Dim tPOS as POINTAPI
Dim sTmp as string
Dim lColor as Long
Dim lDC as Long
'
lDC = GetWindowDC(0)
Call GetCursorPos(tPOS)
lColor = GetPixel(lDC, tPOS.x, tPOS.y)
Label2.BackColor = lColor
'
sTmp = Right$("000000" & Hex(lColor), 6)
Caption = "R:" & Right$(sTmp, 2) & " G:" & mid$(sTmp, 3, 2) & " B:" & Left$(sTmp, 2)
End Sub