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
下面有壹個例子:對妳有借鑒:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Sub Form_Load()
Me.ScaleMode = 3
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim x1, x2, y1, y2 As Integer
Dim color As Long
x1 = 0
x2 = Me.Width
y1 = 0
y2 = Me.Height
Dim r1, g1, b1 As Integer
If (x1 < X < x2 And y1 < Y < y2) Then
color = GetPixel(Me.hdc, X, Y)
Debug.Print color
If color = 0 Then Print X, Y
End If
End Sub