如何同时取得多个坐标点的颜色值?{注意:是同时取得}
例:如何同时取得(10,15).(66,77).(101,108).(203,280)这些坐标点的颜色值?我自己认为应该会利用到放大镜吧!还有,应该要知道如何取得偏移坐标点的颜色值.{这个也回答一下,应该是一起的}
例:鼠标是移到坐标(88,88)的,要取得偏移坐标点(99,99)的颜色值.请问该如何取得?谢谢了!我还想知道如何全面透彻的了解API?我学VB也不久,问题多多!

解决方案 »

  1.   

    'In Module
    Option ExplicitPublic Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Public Type POINTAPI
        x As Long
        y As Long
    End TypePublic Type DGfor3
        ponX As Long
        ponY As Long
        MDC As Long
    End TypePublic Function MouseDC() As DGfor3
        On Error Resume Next
        Dim Cur As POINTAPI
        GetCursorPos Cur
        MouseDC.MDC = WindowFromPoint(Cur.x, Cur.y)
        MouseDC.ponX = Cur.x
        MouseDC.ponY = Cur.y
    End Function
    '-----------------------------------------------------
    'In Form1
    Option ExplicitPrivate Sub Timer1_Timer()
        Picture1.BackColor = GetPixel(GetDC(0), MouseDC.ponX, MouseDC.ponY)
        Me.BackColor = GetPixel(GetDC(0), MouseDC.ponX + 10, MouseDC.ponY + 10)
    End Sub
    '================================
    Picture、Timer各一个。
      

  2.   

    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Sub Command1_Click()
    Dim P As POINTAPI, h As Long, hD As Long, c As Long
        Dim R As Long, G As Long, B As Long
        '第一个点
        P.x = 99
        P.y = 100
        h = WindowFromPoint(P.x, P.y)
        hD = GetDC(h)
        ScreenToClient h, P
        c = GetPixel(hD, P.x, P.y)    R = c And &HFF
        G = (c And &HFF00&) / &H100&
        B = (c And &HFF0000) / &H10000
        Text1.BackColor = RGB(R, G, B)
        
        '第二个点
        P.x = 77
        P.y = 80
        h = WindowFromPoint(P.x, P.y)
        hD = GetDC(h)
        ScreenToClient h, P
        c = GetPixel(hD, P.x, P.y)    R = c And &HFF
        G = (c And &HFF00&) / &H100&
        B = (c And &HFF0000) / &H10000
        Text2.BackColor = RGB(R, G, B)
        
    End Sub