getpixel not working

sdlangers

Well-known member
Joined
Dec 3, 2002
Messages
118
Hi guys, this is a repost - thanks volte force and divil for your help so far...

this code is not returning the correct colors from the desktop.. can anyone see what im doing wrong?

thanks


heres the code...



Code:
 GDI Functions
    Public Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer

     User32 Functions
    Public Declare Function GetDesktopWindow Lib "user32.dll" Alias "GetDesktopWindow" () As IntPtr
    Public Declare Function GetWindowDC Lib "user32.dll" Alias "GetWindowDC" (ByVal ptr As Int32) As IntPtr
    Public Declare Function ReleaseDC Lib "user32.dll" Alias "ReleaseDC" (ByVal hWnd As IntPtr, ByVal hDc As IntPtr) As IntPtr

    Public Function checkPixel(ByVal X As Integer, ByVal Y As Integer) As Integer
        Dim hDC As IntPtr
         Get Desktop hDC
        hDC = GetWindowDC(GetDesktopWindow().ToInt32)
         Get Pixel
        checkPixel = GetPixel(hDC, X, Y)
         Release Desktop hDC
        ReleaseDC(GetDesktopWindow(), hDC)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim c As New Color()
        Dim i As Integer
         get color integer value
        i = checkPixel(100, 50)
         convert to color and display
        c = Color.FromArgb(i)
        MsgBox("Color = " & CStr(i) & " - " & c.R & ", " & c.G & ", " & c.B)
    End Sub
 
robby - thanks.. but that doesnt work.. the getPixel returns an integer value, but it doesnt convert to the correct color

maybe the way im trying to convert it is wrong?

thanks
 
Can you provide the value of i (a few samplings). Ive used GetPixel but I cant remember the value range.
 
thanks robby... okay one value that comes up is

14610415

but it seems to come up no matter what the pixel color is at the X,Y coordinates..

you could cut and paste my above code into a form if you need the example.. thats all the code i have..

thanks
danny.
 
Voltes solution works perfectly, if you want to see the results change then change the colors at that x,y location.
 
great.. ill try that.. it was obviously the way i was trying to convert the int to a color

thanks guys.
 
Back
Top